CODE To enter a TIMESTAMP(8) into a mySQL database

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
User avatar
Slyvampy
Forum Newbie
Posts: 23
Joined: Thu Nov 28, 2002 2:03 am
Location: Yorkshire, England
Contact:

CODE To enter a TIMESTAMP(8) into a mySQL database

Post by Slyvampy »

have a question that no-one in this database either knows or like a few people that have responded to my question in the forum have given me other ways in which still dont work.

Please see

http://www.devnetwork.net/forums/viewto ... highlight=

All i really want to know is how to store this from an input box

$member_date_of_birth

Which has been typed in for example "23-10-1980"

in to a mySQL database as a TIMESTAMP(.

And how to get it out again.

back to $db_member_date_of_birth

so i can output it on another page as

"Monday 23rd October 1980"

Its simple, but yet no-one knows how to do it.

The reason i want it to be a timestamp is because i need it to be sorted within the database, when i run a query.

And also so i can manuiplate the date for example adding two dates together and working out the age of a member.

Can you help? Thanks for reading this anyway.

Cheers,

SteJ.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

To change it to MySQL timestamp format:

Code: Select all

$date = '23-10-1980';
$dateinfo = explode('-', $date);
$mysql_date = $dateinfo[2].$dateinfo[1].$dateinfo[0];
http://www.php.net/manual/en/function.explode.php

To then format that date when getting it out of MySQL use one of MySQL's date and time functions:

Code: Select all

SELECT DATE_FORMAT(date, '%W %D %M %Y') AS date FROM table
http://www.mysql.com/doc/en/Date_and_ti ... tions.html

Mac
Post Reply