Hello,
I have looked everywhere and I cannot find how to compare two dates. I want to see if one date is greater than another. Can I just assign a date to a variable and compare like if dt1 > dt2 then?
Thanks,
Warren
Hello,
I have looked everywhere and I cannot find how to compare two dates. I want to see if one date is greater than another. Can I just assign a date to a variable and compare like if dt1 > dt2 then?
Thanks,
Warren
yes, if you use the standard date format : YYYY-MM-DD
As @nmichaud said, if your dates are in YYYY-MM-DD format or YYMMDD you can get away with comparing the strings numerically. However the best way is to convert the Date (and possible time) into the standard Unix epoch-based time values (i.e. seconds since Jan 1, 1970 at midnight GMT). This is what functions like os.time() return. Once you have two date-times in their seconds value it’s simple math to compare them.
Look at the os.date() and os.time() functions documentation. There should be decent discussion there about how to covert a date to a time value. You can also look through:
http://coronalabs.com/blog/2013/01/15/working-with-time-and-dates-in-corona/
Where we talk about dates and times in a tutorial. The conversion function might be a bit overkill, but it should show you how to use string.match() to parse out the values from a string and get it into a time value.
Rob
yes, if you use the standard date format : YYYY-MM-DD
As @nmichaud said, if your dates are in YYYY-MM-DD format or YYMMDD you can get away with comparing the strings numerically. However the best way is to convert the Date (and possible time) into the standard Unix epoch-based time values (i.e. seconds since Jan 1, 1970 at midnight GMT). This is what functions like os.time() return. Once you have two date-times in their seconds value it’s simple math to compare them.
Look at the os.date() and os.time() functions documentation. There should be decent discussion there about how to covert a date to a time value. You can also look through:
http://coronalabs.com/blog/2013/01/15/working-with-time-and-dates-in-corona/
Where we talk about dates and times in a tutorial. The conversion function might be a bit overkill, but it should show you how to use string.match() to parse out the values from a string and get it into a time value.
Rob