tag:blogger.com,1999:blog-32637828.post3847223185992192494..comments2023-10-31T16:37:25.528+00:00Comments on fahd.blog: Subtract Two Dates [Unix]Fahd Shariffhttp://www.blogger.com/profile/00919911016127601294noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-32637828.post-59947973020467734632014-01-27T13:29:15.425+00:002014-01-27T13:29:15.425+00:00Try this function:
##############################...Try this function:<br /><br />########################################################################################<br /># date2num : calculate daynumber based on year, month and day #<br /># #<br /># Argumemts : gregdate - date in "CCYYMMDD" format #<br /># #<br /># Returns : number of days since 0000-01-01 #<br /># #<br />########################################################################################<br />function date2num( gregdate, _year, _month, _day, _jdays, _epoch, _olympiad, _jaar, _eeuw, _absolute)<br />{<br /> _year = substr(gregdate, 1, 4) + 0<br /> _month = substr(gregdate, 5, 2) + 0<br /> _day = substr(gregdate, 7, 2) + 0<br /> if ((_year % 4 == 0) && ((_year % 100 != 0) || (_year % 400 == 0))) {<br /> split ( "0/31/60/91/121/152/182/213/244/274/305/335/366", _jdays, "/")<br /> }<br /> else {<br /> split ( "0/31/59/90/120/151/181/212/243/273/304/334/365", _jdays, "/")<br /> }<br /> _jaar = _year - 1<br /> _epoch = int( _jaar / 400 )<br /> _jaar -= _epoch * 400<br /> _eeuw = int( _jaar / 100 )<br /> _jaar -= _eeuw * 100<br /> _olympiad = int ( _jaar / 4 )<br /> _jaar -= _olympiad * 4<br /> _absolute = ( _epoch * 146097) + ( _eeuw * 36524 ) + ( _olympiad * 1461 ) + ( _jaar * 365 ) - 1<br /><br /> return _absolute + _jdays[_month] + _day<br />}Anonymoushttps://www.blogger.com/profile/05065856152402321213noreply@blogger.comtag:blogger.com,1999:blog-32637828.post-91574710423967162902009-01-14T22:14:00.000+00:002009-01-14T22:14:00.000+00:00I'm a little bit un-happy with that 365.25 days / ...I'm a little bit un-happy with that 365.25 days / year approximation. What if the two dates substracted are in the same (non-leap) year?<BR/><BR/>I'd go with almost the same idea, just letting bigger brains (awk developers) do the guestimation for me, by using something along the lines of:<BR/><BR/># asume I have the time as hh:mm <BR/><BR/>sub(/:/, " ", time); <BR/>seconds=mktime("2009 01 14 " time " 00");Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-32637828.post-50294700872079615302008-10-10T14:21:00.000+01:002008-10-10T14:21:00.000+01:00Another really helpful titbit.Good work Fahd!!Another really helpful titbit.<BR/>Good work Fahd!!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-32637828.post-72522324784420466512008-09-21T20:17:00.000+01:002008-09-21T20:17:00.000+01:00thanks, it helped me a lot!thanks, it helped me a lot!Anonymousnoreply@blogger.com