in my database I have a time stamp column...which reflects a format like this: 2012-04-02 02:57:54
However I would like to separate them up into $date
and $time
.
after some research through the php manual...I found that date() , date_format() and strtotime() are able to help me to separate them...(not sure if I am right)
but I not very sure of how to code it out...
In my php file...the timestamp extracted would be $row['DATETIMEAPP'].
Will
$date= strtotime('d-m-Y',$row['DATETIMEAPP']); $time= strtotime('Gi.s',$row['DATETIMEAPP']);
or
$date= date('d-m-Y',$row['DATETIMEAPP']);
work?
Can i use date() to get the time as well??
Thanks in advance
Answer: Use the PHP date() Function You can simply use the PHP date() function to get the current data and time in various format, for example, date('d-m-y h:i:s') , date('d/m/y H:i:s') , and so on.
$date = date("yyyy-mm-dd", strtotime(now));
PHP time() Functionecho(date("Y-m-d",$t));
$timestamp = strtotime($row['DATETIMEAPP']);
gives you timestamp, which then you can use date to format:
$date = date('d-m-Y', $timestamp); $time = date('Gi.s', $timestamp);
Alternatively
list($date, $time) = explode('|', date('d-m-Y|Gi.s', $timestamp));
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