Results 1 to 4 of 4

Thread: Date

  1. #1
    Join Date
    Jan 2005

    Unanswered: Date

    I want to ask something rather simple.
    I am creating a client sever aplication and at some cases I want to save at sql server a time (12:00 or 17:15 for example).
    It will be a problem to save at a datetime field of a table only the time (giving the format 10:00 AM for example) or I have to give at a datepicker for example the format to show only time and not all date?
    What is the best?

  2. #2
    Join Date
    Jan 2007
    Provided Answers: 12
    I see nothign wrong sith simply storing the time value in a datetime field, but you must realise that you do technically still get a date part, but this is equivalent to 0.
    In terms of SQL Server, the base date (or 0) is 1900-01-01 00:00:00.000
    To check this out run the following
    SELET DateAdd(hh, 9, 0)
    SELECT Convert(datetime,0)
    However, others may argue that storing the time only as an integer value representing the number of minutes is a better way to go.

    ...and they might be right!
    For example the integer value 60 would represent 1 hour, and the integer value of 540 represents 9 hours.

    The good thing is, no matter which method you choose, you can convert the values into the other very simply.

    Enough from me, I'll let someone opinionate for a while.

    Oh and try this
    DECLARE @c table (dateField datetime)
    INSERT INTO @c(datefield) VALUES('10:00AM')
    INSERT INTO @c(datefield) VALUES ('22:00')
    SELECT dateField FROM @c
    Last edited by gvee; 11-20-07 at 15:34.
    Home | Blog

  3. #3
    Join Date
    Jun 2003
    Provided Answers: 1
    Quote Originally Posted by georgev
    However, others may argue that storing the time only as an integer value representing the number of minutes is a better way to go.
    I would argue with that, but I am tired of arguing for the day, and this seems rather petty compared to my Yak Coral crusades. So Happy Thanksgiving.
    If it's not practically useful, then it's practically useless.

    blindman "sqlblindman"

  4. #4
    Join Date
    Apr 2002
    Toronto, Canada
    there are time durations (e.g. roger bannister, 3:59.4) and there are times of day (e.g. 9:37 a.m.)

    if you are dealing with durations (e.g. what is your average time over your last three races) then i would use DATETIME simply because you can use date arithmetic functions

    if you are dealing with times of day (e.g. what time does the park close) then i might use VARCHAR simply because this allows values like dusk or noon (the former being desirably imprecise and the latter unambiguous as to which 12:00 it's referring to) | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts