store time

databases United States
  • 19 years ago

    how should i store my time value in a table. . . should it be date data type or string data type?


    will i encounter any problem in sorting if its gonna be a string type. . .?


    thanks all!

  • 19 years ago

    I am mostly using Date/Time type... because yes the String data type will be a pain to sort.


    But I guess it depends on what type of date/time you want to use.
    For example, if you have to store duration of a meeting or things like that, you might as well be using just Integer or even byte if it has to be really small amount.


    It might be easier to convert the seconds or minutes into hours yourself to display on forms. That way you are saving database space as well as probably saving a few nano-seconds on queries and search.

  • 19 years ago

    hey thanks! but what if i'm going to store "13:01" ? you mean i have to convert this first to numeric before storing it? if so, that would be useful i guess for operations like getting the difference between two given time. . .is there a function that would restore its numeric equivalent to string to display it again or is it possible to display it directly in its numeric state?


    thanks a lot!

  • 19 years ago

    Yeah I guess it easier to keep information regarding time interval as integer...


    But still, using the Format function you can convert all types of numeric format to a display format. For either Time or Date...


    You might already know this, but let's assume you don't.


    - Time is kept in a decimal format. 24 hours stand in between [0 - 1[. Knowing that, you could find out how much a second is worth. 24 hours = 86400 seconds. So 1 sec would be 1/86400 which is approximately 1.157407.


    - Dates are kept as integer. From Day 0 (which is Dec 30th, 1899) to Today which is Day 37158. If you have a an integer with both decimal and integer parts you then have a complete Date / Time number.


    You can use the following function to display time and dates :


    <code>
    Format(Now(),"dd-mm-yyyy hh:mm")
    </code>
    Will give you : 24-09-2001 13:14
    You can simply use part of it to just display Date or Time as well, just change the "dd-mm-yyy hh:mm" part to what you want it to be.


    The Now() function will give you both Current Date and Time.
    The Date() function will give you current Date
    If you place a number instead, it will translate it to a displayable date / time format.


    Hope that helps

  • 19 years ago

    i'm refreshed! thank you. . .

  • 19 years ago

    i'm refreshed! thank you. . .

  • 19 years ago

    i'm refreshed! thank you. . .

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are 10 types of people in the world, those who can read binary, and those who can't.”