Reputation: 11
I needed to see accordingly to what time is now the following:
if time is between 8:00:00 and 22:00:00 see:
"[[Day shift (current day number) (month name)]]"
and now is the tricky part
if the time is between 22:00:00 and 23:59:59 to see:
"[[Night shift (current day number) - (next day number) (month name)]]"
and if the time is between 00:00:00 and 8:00:00 to see:
"[[Night shift (previous day number) - (current day number) (month name)]]"
Made it to work in Excel I'm not experienced with Python.
=IF(AND(MOD(Sheet4!A1,1)>TIME(8,0,0),MOD(Sheet4!A1,1)TIME(8,0,0),MOD(Sheet4!A1,1)TIME(20,0,0),MOD(Sheet4!A1,1)TIME(20,0,0),MOD(Sheet4!A1,1)TIME(0,0,59),MOD(Sheet4!A1,1)TIME(0,0,59),MOD(Sheet4!A1,1)
I am unable to show you all the excel formula :/ no idea why
in sheet4 a1 put =NOW()
Many Thanks!
Upvotes: 0
Views: 1085
Reputation: 6736
Use the datetime
module:
from datetime import datetime, timedelta
now = datetime.now()
if now.hour < 8:
print("[[Night shift {yesterday.day} - {today.day} {today.month}]]"
.format(today=now, yesterday=now-timedelta(1)))
elif now.hour >= 22:
print("[[Night shift {today.day} - {tomorrow.day} {today.month}]]"
.format(today=now, tomorrow=now+timedelta(1)))
else:
print("[[Day shift {today.day} {today.month}]]".format(today=now))
Upvotes: 2