Jump to content


Photo

Mysq date type


  • Please log in to reply
5 replies to this topic

#1 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 19 April 2006 - 08:07 PM

how to put data into a date type field.I have no problem inputing date into a varchat field but how into a date fi eld.And how to determine the time format ?

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 19 April 2006 - 08:48 PM

A DATE type column doesn't have a time element.

INSERT INTO mytable (datecol) VALUES ('2006-04-19')

if you have a DATETIME column

INSERT INTO mytable (datecol) VALUES ('2006-04-19 21:49:00')

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 20 April 2006 - 11:13 AM

I can recommend storing all your dates and timestamp as UNIX_TIMESTAMP.

All these different time- and dateformats can get really confusing. Always use unix timestamps for al time-related operations, untill you need to display. Php's setlocale() and strftime() will then give you exactly the format you want to display.

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 20 April 2006 - 10:49 PM

I was born in Jan, 1949. Try storing my dob in a unix timestamp.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 21 April 2006 - 09:22 PM

S o i must add this [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--](datecol)[/quote] i n my query ?? ;)

#6 gizmola

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

Posted 21 April 2006 - 10:07 PM

[!--quoteo(post=367324:date=Apr 21 2006, 02:22 PM:name=feri_soft)--][div class=\'quotetop\']QUOTE(feri_soft @ Apr 21 2006, 02:22 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
S o i must add this i n my query ?? ;)
[/quote]

Barand was as clear as he could be. MySQL Date columns have no Time component. If you need a Date + time in one column then you need to use a MySQL DateTime column. You can easily alter your table structure using ALTER TABLE to modify your DATE column to a DATETIME.

If you're still confused try reading this: [a href=\"http://www.gizmola.com/blog/archives/51-Exploring-Mysql-CURDATE-and-NOW.-The-same-but-different..html\" target=\"_blank\"]http://www.gizmola.com/blog/archives/51-Ex...different..html[/a]







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users