Go Back   kirupaForum > Development > Server-Side (PHP, SQL, ASP.NET, etc.)

Reply
 
Thread Tools Display Modes
Old 11-06-2009, 04:51 PM   #1
imagined
Code Remixer
 
imagined's Avatar
Col for Date and another one for Time, or one column for both?

Hey guys!

I don't have too much experience handling time so my question may seem very basic.

I'm going to start adding events to the calendar class I'm writing. It's going to get the events from a MySQL time:
  • name of event
  • date of event
  • time of event
  • description of event
  • duration of event
  • category of event
  • etc

My question is... should I save the TIME and DATE of the event in two different columns or would it be easier to just have the TIME and DATE of the event in ONE column?

__________________
"You are playing a very dangerous game"
"Change always is"

CodeRemix
TutorialRemix
iPhonePaperStudio
imagined is online now   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 11-06-2009, 05:49 PM   #2
blazes
The king of modesty
 
blazes's Avatar
Location Omicron Persei 8

Posts 714
1 TIMESTAMP column will do the job well.

__________________
Kind of like MLA, except for the web and not written by dumb English majors - esherido
blazes is offline   Reply With Quote
Old 11-06-2009, 06:01 PM   #3
imagined
Code Remixer
 
imagined's Avatar
so you recommend using EPOCH then?

__________________
"You are playing a very dangerous game"
"Change always is"

CodeRemix
TutorialRemix
iPhonePaperStudio
imagined is online now   Reply With Quote
Old 11-06-2009, 09:16 PM   #4
blazes
The king of modesty
 
blazes's Avatar
Location Omicron Persei 8

Posts 714
Make the time 'TIMESTAMP' and the default value 'CURRENT_TIMESTAMP'.

__________________
Kind of like MLA, except for the web and not written by dumb English majors - esherido
blazes is offline   Reply With Quote
Old 11-07-2009, 03:07 AM   #5
jsauni
Registered User
 
jsauni's Avatar
Location Auckland, New Zealand

Posts 87
I agree with blazes, 1 timestamp column will do.
jsauni is offline   Reply With Quote
Old 11-07-2009, 06:44 AM   #6
Voetsjoeba
Tu n'es pas un robot!
 
Voetsjoeba's Avatar
Location Belgium, Ghent

Posts 11,537
Keep in mind that TIMESTAMPs have a limited range of roughly 1970 to 2038. If you need a wider range of dates, I suggest you use the DATETIME type instead (1000 to 9999). Also, remember that TIMESTAMP types will automatically perform timezone correction based on the server's current timezone while DATE(TIME) types will not. See MySQL's reference manual on DATE types for more information.

__________________
Wait, what?
Voetsjoeba is offline   Reply With Quote
Old 11-09-2009, 01:31 PM   #7
imagined
Code Remixer
 
imagined's Avatar
Quote:
Originally Posted by Voetsjoeba View Post
Keep in mind that TIMESTAMPs have a limited range of roughly 1970 to 2038. If you need a wider range of dates, I suggest you use the DATETIME type instead (1000 to 9999). Also, remember that TIMESTAMP types will automatically perform timezone correction based on the server's current timezone while DATE(TIME) types will not. See MySQL's reference manual on DATE types for more information.
I think TIMESTAMP may do, the class is intended for an appointments calendar so as long as its the near future it's fine

__________________
"You are playing a very dangerous game"
"Change always is"

CodeRemix
TutorialRemix
iPhonePaperStudio
imagined is online now   Reply With Quote
Old 11-09-2009, 01:34 PM   #8
imagined
Code Remixer
 
imagined's Avatar
Quote:
Originally Posted by blazes View Post
Make the time 'TIMESTAMP' and the default value 'CURRENT_TIMESTAMP'.
Ok then, so let's say I want to input an appointment for November 25, 2009 at 11:00 am

You're saying I should use TIMESTAMP, so then I would input into the database: strtotime('2009-11-25 11:00:00')

Why would it be better to input the TIMESTAMP(1259175600) instead of the actual date and time(2009-11-25 11:00:00)???

I'm sorry the question may seem simple, but I haven't handled time extensively.

__________________
"You are playing a very dangerous game"
"Change always is"

CodeRemix
TutorialRemix
iPhonePaperStudio
imagined is online now   Reply With Quote
Old 11-09-2009, 08:11 PM   #9
blazes
The king of modesty
 
blazes's Avatar
Location Omicron Persei 8

Posts 714
Timestamps are a lot easier to work with. If you have 2009-11-25 11:00:00, but want to display "November 25th, 2009" it's a lot more work than if you used a timestamp because otherwise you have to convert 2009-11-25 11:00:00 to a timestamp, then do the editing.

__________________
Kind of like MLA, except for the web and not written by dumb English majors - esherido
blazes is offline   Reply With Quote
Old 11-09-2009, 08:18 PM   #10
ajcates
Professor Angrypants
 
ajcates's Avatar
Location Vista, California

Posts 1,606
And remember timestamps can be longer then 1970 - 2038 with an extra column in your database.

__________________

http://ajcates.com
ajcates is offline   Reply With Quote
Old 11-09-2009, 11:39 PM   #11
simplistik
PseudoMex
 
simplistik's Avatar
Location Tallahassee, FL

Posts 9,960
Quote:
Originally Posted by blazes View Post
Timestamps are a lot easier to work with. If you have 2009-11-25 11:00:00, but want to display "November 25th, 2009" it's a lot more work than if you used a timestamp because otherwise you have to convert 2009-11-25 11:00:00 to a timestamp, then do the editing.
Not entirely true, that used to be the case

PHP Code:
$datetime = new DateTime('2009-11-25 11:00:00');
echo 
$datetime->format('F dS, Y'); 
Code:
November 25th, 2009
PHP Code:
echo date('F dS, Y'1259146800); 
Code:
November 25th, 2009

http://www.php.net/manual/en/class.datetime.php

In this example a DATETIME is far superior to TIMESTAMP do to it's much larger date range. Also easier to manipulate the date compared to trying to manipulate a timestamp:

PHP Code:
date_add($datetime, new DateInterval('P10D'));
echo 
$datetime->format('F dS, Y'); 
Code:
December 05th, 2009
as well as it's far easier to read the raw data from the DB. Granted you have to have PHP 5.3 or greater, but there's no reason you shouldn't be able to get that on your server, and most good hosts have it already. At the very least create some sort of function that can imitate the native datetime class, if needed/wanted.

__________________
Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.
simplistik is offline   Reply With Quote
Old 11-10-2009, 12:38 PM   #12
imagined
Code Remixer
 
imagined's Avatar
I was practicing with the new DateTime PHP class months ago, so now I will need to review it again.

Need some more practice with OOP. The Calendar class I'm writing is not totally OO, but it's heading that way.

Thanks a lot for your comments guys!

__________________
"You are playing a very dangerous game"
"Change always is"

CodeRemix
TutorialRemix
iPhonePaperStudio
imagined is online now   Reply With Quote
Reply


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 On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:34 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com