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
  11 November 2013
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!
 
  11 November 2013
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.
 
  11 November 2013
oh Klunk, so easy! I could not even imagine! Thank you a lot!!!
 
  11 November 2013
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]
 
  11 November 2013
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.
 
  11 November 2013
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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
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 03:13 AM.


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