calculate the date which was x days ago!

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 11 November 2013   #1
calculate the date which was x days ago!

Please help to calculate and find the date (date/month/year) that was x days ago from current time!

http://stackoverflow.com/questions/...with-javascript

I've found this algorithm, that calculates the duration! I want an universal way - to calculate the date - in any year, any month and so on! Thank you in advance!
 
Old 11 November 2013   #2
fn getDateANumberOfDaysAgo numDays =
     (	
     	timespan = dotnetobject "System.timespan" numDays 0 0 0;
     	today = (dotnetclass "System.DateTime").today;
     	date = today.subtract(timespan);
     	date.tostring(); -- or....
  	--[date.Day, date.Month, date.Year];
     )

Last edited by Klunk : 11 November 2013 at 08:43 AM.
 
Old 11 November 2013   #3
oh Klunk, so easy! I could not even imagine! Thank you a lot!!!
 
Old 11 November 2013   #4
Originally Posted by Klunk:
fn getDateANumberOfDaysAgo numDays =
      (	
      	timespan = dotnetobject "System.timespan" numDays 0 0 0;
      	today = (dotnetclass "System.DateTime").today;
      	date = today.subtract(timespan);
      	date.tostring(); -- or....
   	--[date.Day, date.Month, date.Year];
      )

...or
date.ToShortDateString()
__________________
Looking in the right side. [bgaTools]
 
Old 11 November 2013   #5
Here also a example how to calculate number of days between two dates

 fn GetDaysBetweenDates firstDate: secondDate: =
 (
 	fn checkInput &out date: =
 	(	
 		result = false
 		if try((date.GetType()).fullname == "System.DateTime")catch(false) then (result = true ; out = date)
 		else if (out = try((dotnetclass "System.DateTime").parse date)catch(false)) != false do (result = true)
 		result
 	)
 	if (checkInput &out date:firstDate) then
 	(
 		firstDate = out
 		if (checkInput &out date:secondDate) then
 		(
 			return abs ((out.Subtract(firstDate)).Days)
 		)
 		else messageBox "2nd DateTime is not valid!" title:"Warning" beep:off
 	)
 	else messageBox "1st DateTime is not valid!" title:"Warning" beep:off
 )
 -- now we can use date as string in this form 
 GetDaysBetweenDates firstDate:"3/28/2011" secondDate:"12/17/2013"
 -- or directly add Date Time
 today = (dotnetclass "System.DateTime").today
 newYear = (dotnetclass "System.DateTime").parse "1/1/2014"
 GetDaysBetweenDates firstDate:today secondDate:newYear
 
__________________
Looking in the right side. [bgaTools]

Last edited by gazybara : 11 November 2013 at 10:12 PM.
 
Old 11 November 2013   #6
Thank you, gazybara!!!
 
Old 11 November 2013   #7
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:16 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.