I want to save Fri, 20 Jan 2017 09:27:22 +0200
to MySQL database. In my database table I have TIMESTAMP
What function I should use for inserting this string to MySQL? I tried using date(
Fri, 20 Jan 2017 09:27:22 +0200 )
but when I pass value back to view I get 2017-01-20
in my array. So 1st how to save it correctly? 2nd how to get it back from MySQL back the same as passed?
How to handle your issue:
1) Make and real timestamp from your given date with strtotime()
:
print $timestamp = strtotime('Fri, 20 Jan 2017 09:27:22 +0200');
2) Save the timestamp 1484897242
into the database.
3) Get the timestamp from the database and reformat it:
print date(DATE_RFC2822,$timestamp);//Fri, 20 Jan 2017 09:27:22 +0200
This is what you basicly have to do. Have a try.
Try Carbon,it's laravel core lib, very easy to handle laravel date manipulation. The document link is Carbon
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.