Current location: Hot Scripts Forums » Programming Languages » PHP » How to save a Date in MySQL

How to save a Date in MySQL

Reply
  #1 (permalink)  
Old
Newbie Coder
 
Join Date: Oct 2004
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
How to save a Date in MySQL

Hi,

I'm doing a simple program to store birthdays. I'm trying to save a DATE in my database but the saved data in my BIRTHDAY column is:

0000-00-00 00:00:00

my code is:

$SQL="INSERT INTO employee (employeeID, employeename, Address, Birthday) VALUES ('".$empID."','".$empname."','".$address."', '".$bday."')";

I simply chose the Date/Time format in my database.

I tried to apply $bday = date($bday, "m/d/y") but it didn't work.

Please show me what is wrong with my code.

Thanks for the help and more power.

jozin
Reply With Quote

Featured Marketplace Scripts (view more)

  #2 (permalink)  
Old
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 1 Time in 1 Post
you could do the column DATE type and store the bdate in yyyy-mm-dd format.. other option that i think is alot better is that you make the column bigint format and store the the birthday as a unix timestamp (seconds since 1.1.1970).. that way its alot easyer to format the date as the user wants it (if you have register'd users)
Reply With Quote
  #3 (permalink)  
Old
Junior Code Guru
 
Join Date: Oct 2004
Posts: 460
Thanks: 0
Thanked 0 Times in 0 Posts
hello jozin,
first, please take a look to datetime type in mysql:
http://dev.mysql.com/doc/mysql/en/DATETIME.html

after that, i think you'll discover the way to insert the date to your mysql database.

good luck!!
__________________
just an ignorant noob with moronic solution...
Reply With Quote
  #4 (permalink)  
Old
Banned
 
Join Date: Jun 2004
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
the SQL,
table is what ever you want, i will use the exaple date for the column:

CREATE TABLE w/e (**** **** blah blah, date DATETIME);
you know how to do that I assume, you could also use TIMESTAMP, but i prefer datetime, you can look both up on mysql.com see which one you prefer.
then when you are entering into the database, you use NOW() for the date insert, ex:

INSERT INTO w/e (date) VALUES (NOW());

never put NOW() into ' '

hope that this helps
Reply With Quote
  #5 (permalink)  
Old
Newbie Coder
 
Join Date: Oct 2004
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
How to save a DATE format

Hi Guys,

Thanks a lot for your replies. I've learned a lot about date format and PHP especially the DATETIME.html from moronovich. I sure can use these help in my future projects.

Thanks again and more power,

jozin
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
MySQL to Text File, Plus Limit by Date Korrupt PHP 1 09-11-04 03:21 PM
inserting and retrieving date and time from mysql database stealth04 PHP 5 07-29-04 12:19 PM
Excel document containing records, need to save as a text file to upload to mysql bearslife PHP 1 06-05-04 04:24 AM
Days left to certain date. Data from MySQL alfreds PHP 4 06-17-03 10:26 AM


All times are GMT -5. The time now is 04:48 PM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.