Timestamp Format

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fcarpio
Forum Newbie
Posts: 4
Joined: Thu Mar 03, 2011 10:41 am

Timestamp Format

Post 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
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Re: Timestamp Format

Post by litebearer »

What have you tried thus far? (ie show code)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Timestamp Format

Post 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()).
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
fcarpio
Forum Newbie
Posts: 4
Joined: Thu Mar 03, 2011 10:41 am

Re: Timestamp Format

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Timestamp Format

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
miki
Forum Newbie
Posts: 7
Joined: Fri Mar 18, 2011 2:32 am

Re: Timestamp Format

Post 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
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Timestamp Format

Post by social_experiment »

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
Post Reply