# calculate the date which was x days ago!

 11 November 2013 try2script Expert portfolio Mike Moldova 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! share quote
 11 November 2013 Klunk Lord of the posts   portfolio Klunk United Kingdom ``````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. share quote
 11 November 2013 try2script Expert portfolio Mike Moldova oh Klunk, so easy! I could not even imagine! Thank you a lot!!! share quote
 11 November 2013 gazybara Architect   portfolio Branko Živković Freelancer Niš, Serbia 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] share quote
 11 November 2013 gazybara Architect   portfolio Branko Živković Freelancer Niš, Serbia 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. share quote
 11 November 2013 try2script Expert portfolio Mike Moldova Thank you, gazybara!!! share quote
 11 November 2013 CGTalk Moderation Expert 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. share quote

 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 vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.