I have time strings as follows
8:7:9
17:34:38
I want to check if the strings have H:i:s format if I found completely invalid strings like empty,other text values, strings with date part (2017:10:12 18:39:21)
Thanks in Advance..!
I have time strings as follows
8:7:9
17:34:38
I want to check if the strings have H:i:s format if I found completely invalid strings like empty,other text values, strings with date part (2017:10:12 18:39:21)
Thanks in Advance..!
Use DateTime
to check whether a string matches a specific time format:
if (!DateTime::createFromFormat('H:i:s', '2017-10-08 17:23:30')) {
// time string does not match the H:i:s format
}
If the string matches the provided format, the result will be a DateTime
object. If it doesn't, the result will be a boolean false
. So you can easily check for that.