MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old June 8th, 2003, 06:47 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
mysql datetime or int?

do you prefer to use a datetime or int field for your dates? I had always used int's but a buddy of mine uses datetime and then uses strtotime() to convert it.

what do you do?
__________________
-- Jason

Reply With Quote
  #2  
Old June 8th, 2003, 07:03 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
I use INT( 11 ) as the column and UNIX_TIMESTAMP() as value...
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #3  
Old June 8th, 2003, 07:05 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
does anyone use datetime?

Reply With Quote
  #4  
Old June 9th, 2003, 11:28 AM
Unquick Unquick is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Sarnia, Ontario
Posts: 4 Unquick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I use date personally. That way I can make date comparisions directly in my select statments and also when you do inserts it prevents any funkyness if for example you try to insert a date that doesn't exist you will get an error. I come from a SQL/400 background and I assume it is the same for MySQL.

Reply With Quote
  #5  
Old June 14th, 2003, 02:34 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
I guess my reason for asking is, what are the differences? why would you use INT or DATETIME or DATE over the other?

Reply With Quote
  #6  
Old June 14th, 2003, 02:46 PM
Unquick Unquick is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Sarnia, Ontario
Posts: 4 Unquick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by Taelo
I guess my reason for asking is, what are the differences? why would you use INT or DATETIME or DATE over the other?


Quote:
Originally posted by Taelo
I guess my reason for asking is, what are the differences? why would you use INT or DATETIME or DATE over the other?


Ok INT:
It is for integer and is simply a number; thus you can't do date comparions with it (well you can but you would have to write a complex function to copare dates); furthermore, when you enter a date as an INT, SQL won't know that you are trying to enter a month 13 (there is no such thing a Decembuary and won't give you an error.

DATETIME:
Same as date really, except it also stores the time. Do you need to know the time also? If not then use Date; why store unnessary information and if you have lots of records, it will add to your databases size, so why waste space?

DATE:
If it's a date, use date. Simple as that. Easy to make comparisons you can't enter a month that doesn't exisit without getting an error. This is really important if a user is submitting a form for a delivery for example and you give them three drop down menus with options (year, month, day)... if the user selects June 31 they will get an error - If you used INT, everything would go into the datebase ok and you would have to figure out a way to deliever the customer product on June 31... good luck with that =)

Hope this helps. Let me know.

Reply With Quote
  #7  
Old June 14th, 2003, 03:17 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
ahh ok cool,...good info.

Reply With Quote
  #8  
Old June 25th, 2003, 05:25 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
Unquick summed it up pretty well... I don't have much to add besides the fact that you really should be using a date field if your data is date.

You should be using a timestamp if you want to have the exact date and time updated when you make any action on that record.
These are updated automatically.

As a matter of fact, if I were going to use anything other than a date it would be a character field as opposed to an int() field.

At least there are simple functions to bring a date from character to string easily.

Actually, I have an example.

Say you wanted to store this format of date as an int
mm-dd-yyyy

That would never work as int even if you took away the "-"
mmddyyyy would not work as

01022003 because an int field would strip the leading zero and you would be left with this crap:

1022003


You could get away with this if your date is stored as
yyyymmdd, but that just is not always the case.
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #9  
Old October 10th, 2005, 08:16 AM
hardlocke hardlocke is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 1 hardlocke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 33 sec
Reputation Power: 0
hi
i have in my table the date formated with datetime like '2005-10-08 09:53:32'

now i need the data in another database formated as int(11) like 1128881048


how can i do this? has anyone a convert script or something else? i need your help


hardlocke

Reply With Quote
  #10  
Old October 10th, 2005, 08:37 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 956 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 650865 Folding Title: Super Ultimate Folder - Level 2Folding Points: 650865 Folding Title: Super Ultimate Folder - Level 2Folding Points: 650865 Folding Title: Super Ultimate Folder - Level 2Folding Points: 650865 Folding Title: Super Ultimate Folder - Level 2Folding Points: 650865 Folding Title: Super Ultimate Folder - Level 2Folding Points: 650865 Folding Title: Super Ultimate Folder - Level 2Folding Points: 650865 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 8 h 23 m 32 sec
Reputation Power: 4
Send a message via ICQ to Itsacon
Use the function UNIX_TIMESTAMP(), it converts a date column to a unix timestamp (nr of seconds since 1970-01-01 00:00:00), which is what you want...

See here for details.
__________________
This is my code. Is it not nifty?

"The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools."
---Douglas Adams


Join the Itsacon fanclub!    
Zero Tolerance: Spammers banned so far: 264

Reply With Quote
  #11  
Old October 10th, 2005, 08:56 AM
Laban Laban is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 40 Laban User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 15 m 32 sec
Reputation Power: 4
I use date / datetime...cause that is the correct way of doing it in my mind... :P

And you never know when you might feel the need to use that particular information onwards in any development of the site.
Comments on this post
Itsacon agrees: Or as we say: never send a string to do an int's job

Reply With Quote
  #12  
Old October 10th, 2005, 09:32 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 956 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 650865 Folding Title: Super Ultimate Folder - Level 2Folding Points: 650865 Folding Title: Super Ultimate Folder - Level 2Folding Points: 650865 Folding Title: Super Ultimate Folder - Level 2Folding Points: 650865 Folding Title: Super Ultimate Folder - Level 2Folding Points: 650865 Folding Title: Super Ultimate Folder - Level 2Folding Points: 650865 Folding Title: Super Ultimate Folder - Level 2Folding Points: 650865 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 8 h 23 m 32 sec
Reputation Power: 4
Send a message via ICQ to Itsacon
Quote:
Originally Posted by Laban
I use date / datetime...cause that is the correct way of doing it in my mind... :P

And you never know when you might feel the need to use that particular information onwards in any development of the site.
What he said....

Reply With Quote
  #13  
Old October 11th, 2005, 07:48 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
Wow, a two year old thread.

Why would one use an Int field?
I've always used DATE or DATETIME
UNIXTIMESTAMP make sense as well, but I would never declare a plain old INT.

Reply With Quote
  #14  
Old October 11th, 2005, 08:33 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
Quote:
Quote:
Originally Posted by Laban
I use date / datetime...cause that is the correct way of doing it in my mind... :P

And you never know when you might feel the need to use that particular information onwards in any development of the site.


Quoted for Truth

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > mysql datetime or int?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump