Pandas Date and time

Current Date and time
import pandas as pd 
print(pd.to_datetime('now'))
Output
2022-06-10 12:13:23.001423
Any Date and time
present_time=pd.to_datetime('12252020:233445',format='%m%d%Y:%H%M%S')
Using any date and time
import pandas as pd 
tm=pd.to_datetime('2020-12-29 18:15:05')
# Use day,month, year, hour , second , dayofweek, day_name()
print(tm.minute) 
import pandas as pd 
my_dict={'NAME':['Ravi','Raju','Alex','Ron','King'],
  'dt_start':['2020-12-28 18:15:05', '2021-01-31 23:15:45',
   '2021-02-14 04:15:37', '2021-05-17 09:15:26','2022-06-20 13:45:54']
         }
my_data = pd.DataFrame(data=my_dict)
my_data['dt_start'] = pd.to_datetime(my_data['dt_start'])

print(my_data)
Managing Date
to_datetime()Converting to Datetime
to_timedelta()Convert argument to timedelta for calculation
date_range()Generating range of Date and time
period_range()Generating fixed frequency Datetime index
strftime()Generating Date and time using format
timedelta64()Date and time calculations using different Units
Timestamp()Using Timestamp from Date and time inputs
Dateoffset()Adding or Subtracting date parts
resample()Resampling datetime index using different frequencies
Exercise datetime 3-1 Exercise datetime 3-2 Exercise datetime 3-3

Date & time offset Aliases

AliasDescription
B business day frequency
C custom business day frequency
D calendar day frequency
W weekly frequency
M month end frequency
SM semi-month end frequency (15th and end of month)
BM business month end frequency
CBM custom business month end frequency
MSmonth start frequency
SMS semi-month start frequency (1st and 15th)
BMS business month start frequency
CBMScustom business month start frequency
Q quarter end frequency
BQ business quarter end frequency
QS quarter start frequency
BQS business quarter start frequency
A,Y year end frequency
BA,BY business year end frequency
AS,YS year start frequency
BAS, BYSbusiness year start frequency
BHbusiness hour frequency
Hhourly frequency
T,min minutely frequency
S secondly frequency
L,ms milliseconds
U,us microseconds
N nanoseconds

Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer