Date modification
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
- 
				scott47303
- Posts: 17
- Joined: Tue Aug 10, 2010 3:16 pm
Date modification
OK, i have a date  such as 01-June-2010, and i want to subtract 14 days from it, and I am getting stumped.  I tried to convert to dateitems, to change it but I guess it does not work since it doesnt like the input format?
			
			
									
									
						Re: Date modification
Scott,
This function return the short date one week before
I hope this help
Best
Jean-Marc
			
			
									
									This function return the short date one week before
I hope this help
Code: Select all
function OneWeekBefore
   put the date into mydate
   convert mydate to seconds
   subtract (86400*7) from mydate
   convert mydate to short date
   return mydate
end OneWeekBefore
Jean-Marc
https://alternatic.ch
						- 
				Janschenkel
- VIP Livecode Opensource Backer 
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
Re: Date modification
You're right, the engine doesn't know how to convert from your input format to its internal format.
Something like this should do the trick:
Note the line convert tDate from dateItems to dateItems - it looks odd, but it triggers the engine into re-calculating the date items, automatically rectifying sout-of-bounds months, days, hours, minutes and seconds. Also note that I used 12 (noon) as the hour to avoid surprises due to daylight savings time; may not be necessary, but better safe than sorry 
HTH,
Jan Schenkel.
			
			
									
									Something like this should do the trick:
Code: Select all
on mouseUp
   local tDate
   put ConvertToDateItems("01-June-2010") into tDate
   subtract 14 from item 3 of tDate
   convert tDate from dateItems to dateItems
   answer ConvertFromDateItems(tDate)
end mouseUp
function ConvertToDateItems pDisplayDate
   local tDateItems
   set the itemDelimiter to "-"
   put item 3 of pDisplayDate & "," & \
          lineOffset(item 2 of pDisplayDate, the monthNames) & "," & \
          item 1 of pDisplayDate & ",12,0,0,0" \
          into tDateItems 
   return tDateItems
end ConvertToDateItems
function ConvertFromDateItems pDateItems
   local tDisplayDate
   set the itemDelimiter to ","
   put format("%2u", item 3 of pDateItems) & "-" & \
          line (item 2 of pDateItems) of the monthNames & "-" & \
          format("%4u", item 1 of pDateItems) \
          into tDisplayDate
   return tDisplayDate
end ConvertFromDateItems
HTH,
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
						www.quartam.com