Hi guys.
I want to get the current time in this format : 'YYYY-MM-DD hh:mm:ss',
- I tried the long and short formats but I need this one.
afterwards I need to verify if this date is between two other dates.
- I get the other dates from the database, thats why I think it needs to be in the format, but I am not entirly sure about it.
Happy to get some thoughts about this.
Date & time format 'YYYY-MM-DD hh:mm:ss'
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Date & time format 'YYYY-MM-DD hh:mm:ss'
Hi Fanny,
do it yourself!
Create a function for this like this one, it could of course be a lot shorter, but I wanted to show you the exact way to the solution:
Best
Klaus
do it yourself!
Create a function for this like this one, it could of course be a lot shorter, but I wanted to show you the exact way to the solution:
Code: Select all
on mouseUp pMouseButton
answer your_date_time_format()
end mouseUp
Code: Select all
function your_date_time_format
put the date into tDateShort
put the long date into tDateLong
## Now we need to construct your desired date/time string
## We take the YEAR from long date:
put word -1 of tDateLong into tYear
## -> 2021
## Now to the MONTH and DAY -> 6/22/21
set itemdel to "/"
put item 2 of tDateShort into tDay
## -> 22
put item 1 of tDateShort into tMonth
## -> 6
## Now we have to make sure we have a leading ZERO for days and month < 10
if the num of chars of tDay = 1 then
put 0 before tDay
end if
if the num of chars of tMonth = 1 then
put 0 before tMonth
end if
## Now the long time but without the english AM/PM:
set the twelvehourtime to FALSE
put the long time into tTime
## -> 16:37:27
## OK, done now return the complete data:
return tYear & "-" & tMonth & "-" & tDay && tTime
end your_date_time_format
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Date & time format 'YYYY-MM-DD hh:mm:ss'
Hi.
Know that earlier dates than the beginning of 1970 can also be used. But if you step through the above function, you will see that the seconds return negative values. Not a problem unless your dates are earlier than medieval times. See this silly thread:
viewtopic.php?f=9&t=26619&p=138530&hili ... ng#p138530
Craig
You need to compare the "seconds" from both dates to see if they are before or after your target date:afterwards I need to verify if this date is between two other dates.
Code: Select all
on mouseUp
put "12/7/98" into firstDate
put "7/6/1999" into secondDate
put "1/5/1999" into targetDate
answer isDateBetween(firstDate,secondDate,targetDate)
end mouseUp
function isDateBetween firstDate secondDate targetDate
convert firstDate to seconds
convert secondDate to seconds
convert targetDate to seconds
return targetDate > firstDate and targetDate < secondDate
end isDateBetween
viewtopic.php?f=9&t=26619&p=138530&hili ... ng#p138530
Craig