0% found this document useful (0 votes)
24 views2 pages

Date - Manipulation

not useful

Uploaded by

deepankesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Date - Manipulation

not useful

Uploaded by

deepankesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Python DateTime,TimeDelta,Strftime(Format with Examples

-----------------------------------------------------------
-date
-time
-datetime
-timedelta
-tzinfo

from datetime import date


from datetime import time
from datetime import datetime

today=date.today(
218-1-12
print("date components",today.day,today.month,today.year
date component 12 1 218
today week day number:
mon
tue 1
wed 3
sun 6
today.weekday(
4
python current date and time
from datetime import datetime
today=datetime.now(
218-1-12 11:59:35.976715
DAtetime object
current time without date
----------------------------
t=datetime.time(datetime.now(

weekday indexer to our weekday's arraylist to know which date is today


-------------------
wd=date.weekday(todday
4
days[wd]
friday

formatting function to format date and time


from datetime import datetime
now=datetime.now(
peint(now.strftime("%Y"
218
control coe
------
%Y%y-year,%a%A-weekday,%b%B-month,%d-day of month
"%Y" resemble year with century 218
"%y" full year with century 18

can declaree date,day,month,year seperately

%a,%d %B,%y
Fri,12 January,18
if %a replaced with %A then
Friday
%C local date and time
%x local date
%X local time

12\24 hr format of time


----------------
now=datetime.now(
now.strftime("%I:%M:%S %p"

#%I/%H 12/24 hours, %M-MINUTE, %S-seconds %p -local,s AM\PM

1:19:18 AM
"%H%M"
13:19

TImedelta object to estimate the time in both future and past


------------------------------------------------------------
from datatime import timedelta
timedelta(days=365, hours=8,minutes=15
we constructed basic time delta and printed it
365 days, 8:15:

to get a date a year from now


------------------------------
print("one year from now it will be:"+str(datetime.now(+timedelta(days=365
219-1-12 14:43:18.47611
one week 4 days from current
str(datetime.now(+timedelta(weeks=1, days=4

how many days past new year


------------------------------
today=date.today(
nyd=date(today.year,1,1
(today-nyd.days
11

You might also like