Ashwin
Ashwin

Reputation: 455

convert "DD/MM/YYYY h:m" to timestamp

I need to convert DD/MM/YYYY h:m eg 21/12/2015 17:14 this date to timestamp format using php and store it in mysql.

I have tried strtotime() and some other functions but it's not working. Can any one help me on this. I'm using datepicker to generate the value for date time

Upvotes: 1

Views: 9098

Answers (2)

Chetan Ameta
Chetan Ameta

Reputation: 7896

you can use DateTime class:

$dateStr = '21/12/2015 17:14';
echo $timestamp = \DateTime::createFromFormat('d/m/Y H:i', $dateStr)->getTimestamp();

Upvotes: 1

Vipin Singh
Vipin Singh

Reputation: 543

Use following code to convert "DD/MM/YYYY h:m" into timestamp

$dateString = "21/12/2015 17:14";
$timestamp = strtotime(str_replace("/", "-", $dateString));

Upvotes: 2

Related Questions