STRTOTIME

I have sầu a database row whose type is "timestamp". It automatically populates each time a new record has been added with the time of that record"s insertion. Right now for one of the records it holds the value:

$timeStamp = $row<"date">;$timeStamp = date( "m/d/Y", $timeStamp);But it returns this:


php mysql
Share
Improve sầu this question
Follow
asked Jun trăng tròn "10 at 20:59
*

JamesJames
9511 gold badge11 silver badge33 bronze badges
Add a comment |

3 Answers 3


Active Oldest Votes
13
Use strtotime function:

The timestamp field updates automatically but you can disable that behavior by changing it to DEFAULT CURRENT_TIMESTAMP otherwise it will auto update. From the manual:

In a CREATE TABLE statement, the first TIMESTAMPhường column can be declared in any of the following ways:

With both DEFAULT CURRENT_TIMESTAMPhường and ON UPDATE CURRENT_TIMESTAMP. clauses, the column has the current timestamp for its default value, and is automatically updated.

Bạn đang xem: Strtotime

With neither DEFAULT nor ON UPDATE clauses, it is the same as DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP..

With a DEFAULT CURRENT_TIMESTAMP clause & no ON UPDATE clause, the column has the current timestamp for its mặc định value but is not automatically updated.


Share
Improve sầu this answer
Follow
edited Jun 20 "10 at 21:13
answered Jun trăng tròn "10 at 21:03
*

SarfrazSarfraz
358k7070 gold badges515515 silver badges563563 bronze badges
0
Add a phản hồi |
2
strtotime($timeStamp) (string lớn time) is what you want khổng lồ convert into a unix timestamp.

Then you can use the date on that, so something lượt thích date( "m/d/Y", strtotime($timeStamp) )

http://php.net/manual/en/function.strtotime.php


Share
Improve this answer
Follow
answered Jun 20 "10 at 21:05
*

Aaron YodaikenAaron Yodaiken
17.8k3030 gold badges9595 silver badges176176 bronze badges
Add a phản hồi |
0
SELECT UNIX_TIMESTAMP(sql_row_with_timestamp) AS some_much_more_readable_name FROM your_table should bởi the triông xã.

Xem thêm: sxsw là gì


Share
Improve sầu this answer
Follow
edited Aquảng cáo 12 "18 at 13:04
*

mickmackusa
34.1k1111 gold badges6060 silver badges9191 bronze badges
answered Jun đôi mươi "10 at 21:26
*

cyphercypher
6,60433 gold badges2929 silver badges4646 bronze badges
Add a bình luận |

Your Answer


Thanks for contributing an answer lớn Stack Overflow!

Please be sure to answer the question. Provide details and cốt truyện your research!

But avoid

Asking for help, clarification, or responding to lớn other answers.Making statements based on opinion; baông xã them up with references or personal experience.

To learn more, see our tips on writing great answers.


Draft saved
Draft discarded

Sign up or log in


Sign up using Google
Sign up using Facebook
Sign up using Thư điện tử & Password
Submit

Post as a guest


Name
E-Mail Required, but never shown


Post as a guest


Name
Email

Required, but never shown


Post Your Answer Disthẻ

By clicking “Post Your Answer”, you agree khổng lồ our terms of service, privacy policy và cookie policy


Not the answer you're looking for? Browse other questions tagged php mysql or ask your own question.


The Overflow Blog
Featured on Meta
Linked
0
How khổng lồ format date with carbon format() before converting to json
Related
2773
How can I prevent Squốc lộ injection in PHP?
1308
How can I output MySquốc lộ query results in CSV format?
2767
Deleting an element from an array in PHP
2875
Should I use the datetime or timestamp data type in MySQL?
1847
How bởi I get PHPhường errors khổng lồ display?
2570
How bởi vì I get a YouTube video thumbnail from the YouTube API?
2202
How vày you parse & process HTML/XML in PHP?
4765
Reference — What does this symbol mean in PHP?
2142
How does PHP 'foreach' actually work?
2603
Why shouldn't I use mysql_* functions in PHP?
Hot Network Questions more hot questions

Question feed
Subscribe to lớn RSS
Question feed To subscribe to this RSS feed, copy and paste this URL into lớn your RSS reader.


default
Staông xã Overflow
Products
Company
Staông xã Exchange Network
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.8.5.39930


Staông chồng Overflow works best with JavaScript enabled
*

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device và discthua trận information in accordance with our Cookie Policy.