Boruah
Boruah

Reputation: 45

how to implement String value to date formate

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

Answers (2)

dchrastil
dchrastil

Reputation: 592

How about:

function getTime($date) {
    $timestamp = strtotime((string)$date);
    return date("m-d-Y H:i:s", $timestamp);
}

Upvotes: 0

Norbert Orzechowicz
Norbert Orzechowicz

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

Related Questions