Questions tagged [python-datetime]

Python's built-in datetime module provides classes for manipulating dates and times in both simple and complex ways.

Python's built-in datetime module provides classes for manipulating dates and times in both simple and complex ways.

View on Python docs - for Python 2 and Python 3.

1880 questions
0
votes
2 answers

Convert dataframe column to datetime only if length of string is not zero

I'd like to convert a dataframe column which has a date string. But in some cases, the date string might be empty due to certain conditions. So I just want all the other rows in that column to be converted to datetime format except the rows in that…
0
votes
3 answers

Converting string to a datetime when the string doesn't match a specific date format

I'm having some trouble getting the following string converted to a datetime object using Python. I have a large csv file (over 10k lines) and I need to transform a column of dates from the following format: Jun 1, 2020 12:11:49 AM…
Chowdahhh
  • 117
  • 10
0
votes
3 answers

Set current time and date as default in django model

How can I set the default value as current date and time in a model? my model is : class StudUni(models.Model): student_id = models.IntegerField(blank=True, null=True) uni_name = models.CharField(max_length=55, blank=True, null=True) …
Leman Kirme
  • 530
  • 1
  • 5
  • 19
0
votes
1 answer

Python convert raw GMT to othertime zone e.g SGT

I am trying to convert from GMT to e.g SGT: For example, the value 0348 GMT should be 11:48 am 1059 GMT should be 6:59 pm how do i do this? i have tried: date="03:48" curr = ( dt.datetime.strptime(date, "%H:%M") …
0
votes
1 answer

Transforming date format in python

I want to convert this date format 2020-07-24T19:49:58+03:00 in timestamp. I have tried with datetime but without success: data="2020-07-24T19:49:58+03:00" print (data) date_time = datetime.datetime(data, '%Y %m %d %% %H:%M') #date_time =…
0
votes
1 answer

Python convert epoch time to day or night with date

I'm really new to python. I have a dataset containing epoch time and want to create two new columns(one for Date and another one for Shift(Day or night[6 AM-6 PM belongs to Day and 6 PM to 6 AM belongs to NIGHT])). Heres my data frame: What I…
user13419531
0
votes
2 answers

Python check if time is in the format HH:MMa or HH:MMp

Is there a way to check if a time (represented as string) is in the format 'HH:MMa' or 'HH:MMp'? For example, '12:30p', '11:30a', or '8:30p' could be an input time (where a = am, p = pm). Thanks!
swing1234
  • 233
  • 1
  • 3
  • 13
0
votes
2 answers

Python : time difference between two columns in hours

I have below two columns in this dataframe. DATE1 DATE2 2020-07-08 23:54:17.0 2020-07-09 19:00:56.9970000 2020-07-08 08:22:28.0 2020-07-08 13:23:10.3630000 2020-07-08 10:24:25.0 2020-07-08…
0
votes
2 answers

Django, how to set duration field to be the diffrence between two datetime fields

I have a Django model where I'd like to calculate a duration field based on the inputted data from two DateTime fields and store the difference between them in hours: minutes (I'm not even sure the duration field is the right choice here. This is…
user12177026
0
votes
1 answer

How to add a countdown timer as a user field in django?

I want for every user on an application that they have a field with a certain time, which gets used up when using the website. So if you have an account with 10 hours, there is a field that counts down those 10 hours. Is there any existing way how…
Alec
  • 1
  • 3
0
votes
2 answers

how to concat yesterday datetime and given hours, minutes in python?

I have to transform a string 'yesterday 14:56' to string '19 july 2020 14:56'. if it is 'today 13:20', it must be string '20 july 2020 13:20'. i have a function: new_dates =[ ['yesterday', '18:27'], ['today', '01:47'], ['yesterday',…
ERJAN
  • 23,696
  • 23
  • 72
  • 146
0
votes
1 answer

.logs file to .csv file wih pandas

33 HEIGHT 5 5 INFO ABSENT FROM SCHOOL 123 He has been absent for 48 hours NOLAN Time:2020-07-14 12:34:08 PAUL So I have a log file that looks like this above.…
0
votes
2 answers

TypeError: can't compare offset-naive and offset-aware times

I have this function for checking a specific time and day in the week. It should print 1 from Sunday 7:00PM to Friday 8:00PM And print 0 from Friday 8:00PM to Sunday 7:00PM I checked the function on Friday around 11:00AM and 2:00PM and I'm getting…
Kinnturo
  • 141
  • 1
  • 2
  • 13
0
votes
2 answers

I want to get the user date of birth in python

bdate = input("Type your Date of birth (ie.10/11/2011) : ") print(bdate) day, month, year = map(int, bdate.split('/')) birth_date = datetime.date(day, month, year) print(birth_date) today = datetime.datetime.now().strftime("%Y") print(today) age =…
0
votes
1 answer

How do I extract year/hour/day data from pandas Timestamp object in C++?

I am working on a project with embedded Python in C++ and have run into an issue with pandas DataFrames with datetimes/Timestamps. When adding datetime objects to pandas, if they are within the range of Timestamp they seem to get auto-converted into…