This question already has answers here:
Getting today's date in YYYY-MM-DD in Python?
(12 answers)
Closed 4 years ago.
I need to get the current date but in this format:
<dd>/<mm>/<yyyy>
Is there any method that i can use?
I only found different formats and things I can't use for now.
For working with python.
Try this:
from datetime import date
timeNow = str(datetime.now())
print(timeNow)
import datetime
d = datetime.datetime.today()
print (datetime.date.strftime(d, "%d/%m/%y"))
Related
This question already has answers here:
How to define format when using pandas to_datetime?
(2 answers)
Convert Pandas Column to DateTime
(8 answers)
Closed 5 months ago.
Does anyone know how to change 20130526T150000 to datetime format?
One note: the 'T' is usefull. Use pd.to_datetime() directly, the T is actually usefull as it denotes the iso format and will help not confuse for some locales (some countries have the month first, then the day, others the oposite - iso goes from most significant to less: year, month, day)...
pd.to_datetime("20130526T150000")
Timestamp('2013-05-26 15:00:00')
If you want to be more explicit, specify the format:
pd.to_datetime("20130526T150000", format=...)
However, this might be a duplicate: How to define format when using pandas to_datetime? ... For best results, if you are doing a conversion of a column, use Convert Pandas Column to DateTime
This question already has answers here:
How do I parse an ISO 8601-formatted date?
(29 answers)
Parsing date, time and zone to UTC datetime object
(1 answer)
Closed 9 months ago.
I have datetime value in format of 2022-01-26T07:01:36-08:00 (based on which user fetches data, it will have local timezone, like -08:00, +05:30)
I want to convert this time into UTC Time.
I saw multiple example of pytz but couldn't figure out how to convert using pytz or datetime. datetime value will be based on machine timezone so I can't hard code timezone value also.
This question already has answers here:
Convert date from excel in number format to date format python [duplicate]
(2 answers)
Convert Excel style date with pandas
(3 answers)
Closed 1 year ago.
I'd like to convert a column to date. My source data is from an Excel which is already formatted to date data type. However, when pandas read my file the date columns are read as e.g.'44249'
I tried the following code
RPT["Pot"] =`RPT["Pot"].apply(lambda x: pd.to_datetime(x, format='%d%m%Y'))
but I got the error time data '44249' does not match format '%d%m%Y' (match).
I also tried this code:
RPT["PLANNED SUBMISSION DATE TO E&P"] = pd.to_datetime(RPT["PLANNED SUBMISSION DATE TO E&P"])
but the results were 1970-01-01 00:00:00.000044365, which inaccurate.
Can I anyone please help me?
This question already has answers here:
Cleanest and most Pythonic way to get tomorrow's date?
(7 answers)
Closed 1 year ago.
I want to get tommorow's date as datetime.date object just like "datetime.date.today()".
I Need to use strftime() on it so timedelta is not an option.
Thanks in advance!
Try this:
>>> import datetime
>>> datetime.date.today() + datetime.timedelta(days=1)
Try this:
import time
import datetime
cur_tim=time.localtime(time.time() + 24*3600)
datetime.date(cur_tim[0],cur_tim[1],cur_tim[2])
This question already has answers here:
How do I get the UTC time of "midnight" for a given timezone?
(6 answers)
Closed 8 years ago.
I'm working in django, but standard python solution is ok too.
I'm converting a code which uses a naive-datetime to use aware-datetime.
Below is the original code:
today = datetime.today()
MyClass.objects.filter(datetimefield__range=(today, today+datetime.timedelta(1)) )
How do I convert it to use timezone-aware time?
If the time is jun/3rd/7:20pm locally,
I'd like to get datetime range of [jun/3rd/00:00am, jun/4th/00:00am]
(midnight to midnight which will include now)
I know this is very old, but using django.utils.timezone this is fairly straightforward.
(nothing concerning timezones ever seems easy to me)
# this is could be any datetime.date
my_date = timezone.now().date()
dt_at_local_midnight = timezone.make_aware(
timezone.datetime.combine(my_date, time.min),
timezone.get_current_timezone())
and alternative that might be better is listed in the first comment below.