Convert to mysql 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
aspekt9
Forum Commoner
Posts: 43
Joined: Wed Dec 06, 2006 5:03 pm

Convert to mysql timestamp format?

Post by aspekt9 »

How can I convert this: 200703162636

To mysql timestamp format (YYYY-MM-DD HH:MM:SS)?

and if the day is 1 it'll put a 0 in front of it?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

select from_unixtime($timestamp);
aspekt9
Forum Commoner
Posts: 43
Joined: Wed Dec 06, 2006 5:03 pm

Post by aspekt9 »

The unix timestamped isn't stored in the database though. It's retrieved from a form where the user selects the date and time.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

That's not a unix time stamp, but a textual time stamp that MySQL can understand already.
User avatar
the_last_tamurai
Forum Commoner
Posts: 87
Joined: Wed Feb 28, 2007 8:24 am
Location: cairo
Contact:

Post by the_last_tamurai »

aspekt9 : what is the problem ??
the first form is unix timestamp....and you can easily insert it to database as integer
and play with it bygetdate()
that's what I extract from your question????isn't it??
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

How can I convert this: 200703162636
What is this 200703162636? Is it a numeric value made up of date parts, or a time stamp, or what? How does it get into that format?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

As I said, it's not a unix time stamp.

It is in MySQL's timestamp field format. It is legible by MySQL without any special help. Yes, it is composed of date parts without separators. Why? Because there's no need when there is known uniform width for all elements.
User avatar
the_last_tamurai
Forum Commoner
Posts: 87
Joined: Wed Feb 28, 2007 8:24 am
Location: cairo
Contact:

Post by the_last_tamurai »

:? lol, I didn't notice that the first form is a date without separators
yes, it's not unix timestamp
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Search the MySQL manual for Date and Time functions for a huge list of things you can do with a datetime stamp.
Post Reply