Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
ittarter
- Posts: 151
- Joined: Sat Jun 13, 2015 2:13 pm
Post
by ittarter » Thu Feb 11, 2016 12:34 pm
Code: Select all
if "2/9/16" > "2/11/16" then; put "OK"; end if
Results in "OK"
I'm guessing that the front slashes are being read as divide signs.
Besides converting to seconds, is it possible to compare dates in terms of which is later/earlier? Or do I have to convert to seconds and then compare?
-
Thierry
- VIP Livecode Opensource Backer

- Posts: 875
- Joined: Wed Nov 22, 2006 3:42 pm
Post
by Thierry » Thu Feb 11, 2016 12:41 pm
ittarter wrote:Code: Select all
if "2/9/16" > "2/11/16" then; put "OK"; end if
Results in "OK"
Mmm, try this one:
Code: Select all
if "9/12/1999" > "1/1/2016" then put "Ok"
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
-
ittarter
- Posts: 151
- Joined: Sat Jun 13, 2015 2:13 pm
Post
by ittarter » Thu Feb 11, 2016 1:16 pm
Nope, it still returns "Ok".
-
Thierry
- VIP Livecode Opensource Backer

- Posts: 875
- Joined: Wed Nov 22, 2006 3:42 pm
Post
by Thierry » Thu Feb 11, 2016 2:52 pm
ittarter wrote:Nope, it still returns "Ok".
Sure it returns the wrong info
I wanted to show you that's not the right method.
Check date or time comparison in this forum;
I'm sure you'll find something.
Good luck,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7389
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Thu Feb 11, 2016 6:44 pm
The short answer is yes, convert to seconds. That's the only way to compare them as numbers.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
quailcreek
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
Post
by quailcreek » Thu Feb 11, 2016 6:45 pm
This might help.
Code: Select all
function numericDate pDate
set the itemDel to slash
-- get the month and pad to 2 digits if necessary
put item 1 of pDate into tMonth
if tMonth < 10 then put "0" before tMonth
-- get the day and pad to 2 digits if necessary
put item 2 of pDate into tDay
if tDay < 10 then put "0" before tDay
-- the year is always 4 digits in the dateItems so just put it together and return the number
return item 3 of pDate & tMonth & tDay
end numericDate
put numericDate(fld "Date Start") into tStart
put numericDate(fld "Date End") into tEnd
if tStart < tEnd then
-- do stuff
end if
Tom
MacBook Pro OS Mojave 10.14
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Thu Feb 11, 2016 7:16 pm
This won't help in the specific case you're exploring, but helpful for other algos: dates can be compared in the sort command when specifying datetime, e.g.:
sort lines of tList datetime
-
ittarter
- Posts: 151
- Joined: Sat Jun 13, 2015 2:13 pm
Post
by ittarter » Mon Feb 15, 2016 12:07 pm
Thanks for the responses, everyone! I'll convert to seconds to compare, and it's helpful to know that I can sort dates, too
