Click to See Complete Forum and Search --> : Datetime Usage


aj_nsc
01-04-2007, 09:52 AM
I'm a fairly new database programmer, I've got a few general concepts under my belt but I'm starting to become more interested in what the specific options for fields do and what can be done with them, in this case, date time.

Let's say I'm making a blog program, I want to use a field blogged which is a datetime field to keep track of when each blog was posted. I have a few questions about this:

Is this field filled in automatically every time a record is added or do I have to manually insert the value with the correct format (YYYY-MM-DD HH:MM:SS)?

Can I sort blog entries using this field directly through a MySQL query or do I have to use some other language (i.e. PHP) to abstract the information from the datetime field first and then sort them using PHP?

If I want to display rangers of blogs (say, every entry for July 2006) how would I go about doing this (you can use PHP as an example)?

If sorting the entries into groups is the main concern, is it better to use a datetime field, or a timestamp field, or is there a difference?

Thanks for fielding these questions, everyone on here is so helpful I'm sure these will be answered in no time.

chazzy
01-04-2007, 10:16 AM
in the newer versions of mysql, you can have it auto insert the current date for you when you create the table.
you can also sort using the ORDER BY clause in SQL.

MrCoder
01-10-2007, 07:36 PM
MySQL datetime fields combined with ORDER BY (ASC / DESC) will give you a correct sorting order since a date in the future will always be grater then one in the past if represented as numerical values (YYYY-MM-DD HH:MM:SS)

2007-01-01 01:01:01 = 20070101010101
and is less then
2007-02-01 01:01:01 = 20070201010101

Reverse dating is great, but I miss UNIX timestamps :(

NightShift58
01-11-2007, 04:54 AM
Do you mean this: UNIX_TIMESTAMP()?

MrCoder
01-11-2007, 07:03 AM
Yes, but when was the last time you used it? (honestly) :P

NightShift58
01-11-2007, 12:10 PM
Honestly? Every NOW() and then...