Forum Moderators: coopster

Message Too Old, No Replies

reverse time function in php?

         

topr8

9:29 pm on Oct 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i've a variable (data which has been passed to the application) which should be a date in the format:

YYYY-mm-dd hh:mm:ss

is there a built in php function that checks that this is valid, kind of like a reverse date function if you like

topr8

9:52 pm on Oct 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



well for anyone that finds this in the future, i just wrote a quick function that seems to work

function f_validTimestamp( $value )
{
return preg_match( '`^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$`' , $value ) ;
}

coopster

11:56 am on Oct 28, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



That is only going to validate the format, but not the actual date/time. You can parse the value using your regular expression and then use functions like checkdate [php.net] or better yet mktime [php.net] to be certain that the actual date and time are valid.