Skip to content
Advertisement

Tag: datetime

How to convert `ctime` to `datetime` in Python?

For me at the moment, t is ‘Sat Apr 21 11:58:02 2012’. I have more data like this. My question is: How to convert t to datetime in Python? Are there any modules to to it? I tried to make a time dict and then convert t, but feel like that’s not the best way to do it in Python.

How do I get the day of week given a date?

I want to find out the following: given a date (datetime object), what is the corresponding day of the week? For instance, Sunday is the first day, Monday: second day.. and so on And then if the input is something like today’s date. Example The output is maybe 6 (since it’s Friday) Answer Use weekday(): From the documentation: Return the

Difference between Python datetime vs time modules

I am trying to figure out the differences between the datetime and time modules, and what each should be used for. I know that datetime provides both dates and time. What is the use of the time module? Examples would be appreciated and differences concerning timezones would especially be of interest. Answer The time module is principally for working with

Django DateTimeField auto_now_add not working

In one of the model i have set one timestamp field as follows: While in shell i am able to create a obj and save it, however in my application it is raising a exception that created_datetime field cannot be null. Confused where things went wrong!! How to reslove it. Answer You can do something like this

Convert UTC datetime string to local datetime

I’ve never had to convert time to and from UTC. Recently had a request to have my app be timezone aware, and I’ve been running myself in circles. Lots of information on converting local time to UTC, which I found fairly elementary (maybe I’m doing that wrong as well), but I can not find any information on easily converting the

Advertisement