Subracting dates
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 137
- Joined: Thu Jul 24, 2008 11:22 pm
Subracting dates
I have a date input into a field as 14/10/2008 and "the Date" automatically input into another field. I want to subtract one from another and get a result of days (not hours or minutes) overdue etc. I've had a few goes i guess the input date probably needs to be formatted somehow. Also "the date" is input in American format - ie mmddyy and I need it as ddmmyy. Assistance appreciated.
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
The 'convert' command and the 'system' keyword are your friends.
With 'the system date' you can get the current date in whatever the system format is.
Assuming you have two fields 'Date_1' and 'Date_2' you can get the difference as follows.
And just to give you a hint for a future extension where you want to know what day it is 6 weeks from now.
Hope this helped,
Jan Schenkel.
With 'the system date' you can get the current date in whatever the system format is.
Code: Select all
put the system date into field "Today"
Code: Select all
on mouseUp
put field "Date_1" into tDate1
put field "Date_2" into tDate2
convert tDate1 from system date to seconds
convert tDate2 from system date to seconds
put tDate2 - tDate1 into tDifference
divide tDifference by 60 * 60 * 24
answer "There is a difference of" && tDifference && "days."
end mouseUp
Code: Select all
on mouseUp
put 6 * 7 into tNumDays
put the date into tDate
convert tDate from date to dateItems
add tNumDays to item 3 of tDate
convert tDate from dateItems to system date
answer tNumDays && "days from now is:" && tDate
end mouseUp
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
You may also find it helpful to try the "useSystemDate" property.
It is a local property (so it needs to be set for each handler that may handle dates, and will reset itself at the end of every handler in which it is used).
If you at the top of every handler that caters for dates, then all the dates will be "system" dates and you won't have to change hundreds of lines of code (hopefully).
It is a local property (so it needs to be set for each handler that may handle dates, and will reset itself at the end of every handler in which it is used).
If you
Code: Select all
set the useSystemDate to true
-
- Posts: 137
- Joined: Thu Jul 24, 2008 11:22 pm