Created
March 1, 2017 03:07
-
-
Save aonrobot/6eb4007077c2e6f45035fed1d69c7249 to your computer and use it in GitHub Desktop.
Calculate Number of day created by Auttawut Wiriyakreng - https://repl.it/GBrU/0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import time | |
import datetime | |
def tm(yy,mm,dd): | |
s = str(dd) + "/" + str(mm) + "/" + str(yy) | |
return time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple()) | |
y = 2017 | |
m = 2 | |
d = 2 | |
ynow = 2017 | |
mnow = 3 | |
dnow = 1 | |
t0 = y*12 + m - 1 # total months for birthdate. | |
t = ynow*12 + mnow - 1 # total months for Now. | |
dm = t - t0 # delta months. | |
if dnow >= d: | |
print('Year : ' + str(math.floor(dm/12)) + ' Months : ' + str(dm%12) + ' Day : ' + str(dnow-d)) | |
else: | |
dm = dm - 1 | |
t = t - 1 | |
print(str(tm(ynow,mnow,dnow)) + ' ' + str(tm(math.floor(t/12), (t%12)+1, d)) + ' ' + str(d)) | |
print(str(math.floor(t/12)) + str(t%12+1) + str(d)) | |
if ((math.floor(t/12)%4 == 0 and math.floor(t/12)%100 != 0) or math.floor(t/12) % 400 == 0): | |
d = d | |
print('Year : ' + str(math.floor(dm/12)) + ' Months : ' + str(dm%12) + ' Days : ' + str((tm(ynow,mnow,dnow) - tm(math.floor(t/12), (t%12)+1, d))/60/60/24)) | |
else: | |
#allDay = (tm(ynow,mnow,dnow) - tm(math.floor(t/12), (t%12), d))/60/60/24 | |
allDay = (tm(ynow,mnow,dnow) - tm(y, m, d))/60/60/24 | |
print(allDay) | |
if(m+1 > 12): | |
m = 0 | |
y = y + 1 | |
#print(str(tm(ynow,mnow,dnow)) + " " + str(tm(y, m, d))) | |
betDay = ( (tm(ynow,mnow,1) - 86400) - (tm(y, m+1, 1)) ) /60/60/24 | |
print(allDay-betDay) | |
print('Year : ' + str(math.floor(dm/12)) + ' Months : ' + str(dm%12) + ' Days : ' + str(allDay-betDay-1)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment