Page 1 of 1

Timestamp Format

Posted: Thu Mar 17, 2011 8:48 am
by fcarpio
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

Re: Timestamp Format

Posted: Thu Mar 17, 2011 9:45 am
by litebearer
What have you tried thus far? (ie show code)

Re: Timestamp Format

Posted: Thu Mar 17, 2011 10:31 am
by pickle
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()).

Re: Timestamp Format

Posted: Thu Mar 17, 2011 12:12 pm
by fcarpio
litebearer wrote:What have you tried thus far? (ie show code)
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.

Re: Timestamp Format

Posted: Thu Mar 17, 2011 12:17 pm
by pickle
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.

Re: Timestamp Format

Posted: Fri Mar 18, 2011 3:22 am
by miki
If u just want to output, I suggest u use php function.
If u want to calculate, u can find mysql function in manual

Re: Timestamp Format

Posted: Sat Mar 19, 2011 9:21 am
by social_experiment
MySQL's date_format() function. ( date_format('your_date_field', '%m/%d/%y') )