Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

i want to get only date from datetime variable in php

Tags:

php

mysql

I need to get only date from datetime variable. I was using this code. It was working fine but now I am facing problem when I'm trying to store only date in mysql please. Take a look at the code below and please tell me what I'm missing,

$date_time = "11-Dec-13 8:05:44 AM" 

From the date I got from user input, I need to save only date in att_date variable.

$arr = explode("/", $date_time);
$arr2 = explode(" ", $arr[2]);
$att_date = $arr2[0].'-'.$arr[0].'-'.$arr[1];
like image 681
user3138192 Avatar asked Nov 07 '25 07:11

user3138192


1 Answers

Here is the solution:

$date_time = "11-Dec-13 8:05:44 AM";
$new_date = date("Y-m-d H:i:s",strtotime($date_time));
like image 66
user3045072 Avatar answered Nov 09 '25 05:11

user3045072



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!