Hello,
I am fairly new to coding and I have what is seems to be a trivial problem. I have a database that is recording timestamps for all my transactions. I want to be able to extract the date to a format like MM/DD/YY. Is there a function that will allow me to do this? Right now what I have is YYYY-DD-MM HH:MM:SS.
Thanks for the help.
FC
Timestamp Format
Moderator: General Moderators
-
litebearer
- Forum Contributor
- Posts: 194
- Joined: Sat Mar 27, 2004 5:54 am
Re: Timestamp Format
What have you tried thus far? (ie show code)
Re: Timestamp Format
That date format is the default format for the MySQL DATETIME format. Fortunately, MySQL provides lots of date extraction functions (such as MONTH(), DAY(), YEAR()).
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Timestamp Format
I was trying to explode(" ", $timesstamp) using the first space, the explode("-", $resultOfFirstExplode) to get what I wanted but I realized it was way too cumbersome so I decided to look for other ways before I mess things up. I did specific searched on PHP and date formats but I guess I have to search for MySQL and date formats as mentioned above.litebearer wrote:What have you tried thus far? (ie show code)
Re: Timestamp Format
You can do it in PHP using the strtotime() function, but you're better to do it in MySQL if you're sure of the format you need.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Timestamp Format
If u just want to output, I suggest u use php function.
If u want to calculate, u can find mysql function in manual
If u want to calculate, u can find mysql function in manual
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Timestamp Format
MySQL's date_format() function. ( date_format('your_date_field', '%m/%d/%y') )
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering