Reputation: 45
I have the php code to get string $date from textbox Now how can i
(1)convert the string in to the date formate variable
(2)How to chech $date is Date Variable
Upvotes: 0
Views: 152
Reputation: 592
How about:
function getTime($date) {
$timestamp = strtotime((string)$date);
return date("m-d-Y H:i:s", $timestamp);
}
Upvotes: 0
Reputation: 1311
try {
$date = new DateTime($textbox->getValue());
} cath (Exception $e) {
$errors[] = 'Invald date format, please use Y-m-d H:i:s';
}
if (!($date instanceof DateTime)) {
echo 'Variable $date is not DateTime object!';
}
Upvotes: 2