Jump to content


Invalid Date format

  • Please log in to reply
2 replies to this topic

#1 Tegwin

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 27 May 2003 - 09:56 AM

Invalid Date format
Hello I have set up a database in MySQL which uses the datetime for the columns. I have 2 seperate fields, one for date and one for time. when I display the information, I get the following information

Date 2002-11-09 00:00:00 Time 1899-12-30 20:50:00

The date in the first field is 2002-11-09 and the time in the second filed is 20:50:00 but the date field puts an additional time in as 00:00:00 and the time field has a date of 1899-12-30 .. How can I get rid of these. I want the date only in one field and the time only in the other...

#2 shivabharat

  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 27 May 2003 - 10:30 AM

Try this

Field Type Null Key Default Extra
------ ------------- ------ ------ ------- ------
date date YES (NULL)
time time YES (NULL)

insert into `test`.`test` 

	(date, time)


	(now(), 12:30:00");

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#3 gizmola

  • Administrators
  • Advanced Member
  • 4,664 posts
  • LocationLos Angeles, CA USA

Posted 27 May 2003 - 10:04 PM

The other option is to not use a seperate data and seperate time column, but instead to use a Datetime column.

It\'s also better not to use keywords as the names of your columns. I\'d suggest instead that you have a column called for example:


When inserting a value it could be insert into yourtbl (col1, col2, created) values (\'blah\', \'blah\', now());

It\'s easy enough via either MYSQL or php to seperate the date and time components from a date/time. The added advantage of using a datetime, is that *if* you need to do selects via date, it will be much more efficient. For example, you might have a query like:

select * from yourtbl where created > now()-1;

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users