I have a search box on my website...mysql database. I check currently if the keyword search is a category or just a sentence that matches the title. I would like to enhance that further by detecting if a date is the search keyword, then it will know that and SELECT * posts relevant to that date. How can I detect if it is a date or not? maybe a regular expression?
For your info, I am using the standard format of YYYY/MM/DD so e.g. 2012/07/21.
I'd test it with strtotime()
.
$keyword;
$time = strtotime($keyword);
if ($time !== false) {
// $keyword is a parsable date!
}
You might want to look at the PHP function strtotime()
, which returns a timestamp or FALSE if not a date...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With