Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Storing Time value in Access

Storing Time value in Access

Scheduled Pinned Locked Moved Database
databasecsharpcomtoolsquestion
11 Posts 8 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Richard Blythe
    wrote on last edited by
    #1

    Lately I've been working an C# app that stores values in an Access db. One of the fields stores a time value. (7:30 PM) Is there a more effecient way to store a time value than using the DateTime column? I will need to convert it to a DateTime value in the SELECT query. Serious answers please. :suss:

    Be nice to your kids. They'll choose your nursing home.
    My Articles   Developer's Best Friend

    D L B C 4 Replies Last reply
    0
    • R Richard Blythe

      Lately I've been working an C# app that stores values in an Access db. One of the fields stores a time value. (7:30 PM) Is there a more effecient way to store a time value than using the DateTime column? I will need to convert it to a DateTime value in the SELECT query. Serious answers please. :suss:

      Be nice to your kids. They'll choose your nursing home.
      My Articles   Developer's Best Friend

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      I'm a bit confused. :confused: You say that want a better way to store time in Access, but you will need to convert it to DateTime in your select statement. Then why not store it in a DateTime column to begin with ? I worked for a Time and Attendace company for a while and what I've learned is that you always seem to need the date component along with the time because there is always the overnight shift worker. (11pm to 7am) When you store the data in a DateTime column, the calculation of time difference is already built into those functions, you don't have to worry about crossing midnight etc. My vote is to store the time in a DateTime column. :thumbsup: I'm getting off my soapbox now. ;) Best of luck with your project.

      R 1 Reply Last reply
      0
      • D David Mujica

        I'm a bit confused. :confused: You say that want a better way to store time in Access, but you will need to convert it to DateTime in your select statement. Then why not store it in a DateTime column to begin with ? I worked for a Time and Attendace company for a while and what I've learned is that you always seem to need the date component along with the time because there is always the overnight shift worker. (11pm to 7am) When you store the data in a DateTime column, the calculation of time difference is already built into those functions, you don't have to worry about crossing midnight etc. My vote is to store the time in a DateTime column. :thumbsup: I'm getting off my soapbox now. ;) Best of luck with your project.

        R Offline
        R Offline
        Richard Blythe
        wrote on last edited by
        #3

        The key word here is "store". Access has a max capacity of 2gb. DateTime types require 8 bytes for each field. Some Access developers have advocated using an int type for Date only values. This would be accomplished by storing the number of days since 1900 and using the DateAdd() function to convert the value to DateTime in the SELECT query. I ask for serious responses! :-D

        Be nice to your kids. They'll choose your nursing home.
        My Articles   Developer's Best Friend

        L T M 3 Replies Last reply
        0
        • R Richard Blythe

          The key word here is "store". Access has a max capacity of 2gb. DateTime types require 8 bytes for each field. Some Access developers have advocated using an int type for Date only values. This would be accomplished by storing the number of days since 1900 and using the DateAdd() function to convert the value to DateTime in the SELECT query. I ask for serious responses! :-D

          Be nice to your kids. They'll choose your nursing home.
          My Articles   Developer's Best Friend

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Richard Blythe wrote:

          I ask for serious responses!

          Use a DateTime-field - that's what most people do, and that's where you can expect the most support. You can fit a whole lotta dates in those 2 Gb, and optimizing for space is a bit of a timewaster IMO.

          I are Troll :suss:

          R 1 Reply Last reply
          0
          • L Lost User

            Richard Blythe wrote:

            I ask for serious responses!

            Use a DateTime-field - that's what most people do, and that's where you can expect the most support. You can fit a whole lotta dates in those 2 Gb, and optimizing for space is a bit of a timewaster IMO.

            I are Troll :suss:

            R Offline
            R Offline
            Richard Blythe
            wrote on last edited by
            #5

            Wow that's pretty serious! :) I certainly don't want to create a second curse by trying to eliminate the first one. Thanks for the reply.

            Be nice to your kids. They'll choose your nursing home.
            My Articles   Developer's Best Friend

            1 Reply Last reply
            0
            • R Richard Blythe

              The key word here is "store". Access has a max capacity of 2gb. DateTime types require 8 bytes for each field. Some Access developers have advocated using an int type for Date only values. This would be accomplished by storing the number of days since 1900 and using the DateAdd() function to convert the value to DateTime in the SELECT query. I ask for serious responses! :-D

              Be nice to your kids. They'll choose your nursing home.
              My Articles   Developer's Best Friend

              T Offline
              T Offline
              T M Gray
              wrote on last edited by
              #6

              I ask for serious design. Using Access for something when you are afraid of running into the 2gb limit is terrible. Use SQL Compact Edition or something else. I think the OLE automation date format is only 4 bytes.

              1 Reply Last reply
              0
              • R Richard Blythe

                The key word here is "store". Access has a max capacity of 2gb. DateTime types require 8 bytes for each field. Some Access developers have advocated using an int type for Date only values. This would be accomplished by storing the number of days since 1900 and using the DateAdd() function to convert the value to DateTime in the SELECT query. I ask for serious responses! :-D

                Be nice to your kids. They'll choose your nursing home.
                My Articles   Developer's Best Friend

                M Offline
                M Offline
                Mycroft Holmes
                wrote on last edited by
                #7

                I agree with Mr Gray, if you have to optimise for space using spit Access then you are using the wrong tool. Seriously change tools, there are many better options out there than spit Access

                Never underestimate the power of human stupidity RAH

                1 Reply Last reply
                0
                • R Richard Blythe

                  Lately I've been working an C# app that stores values in an Access db. One of the fields stores a time value. (7:30 PM) Is there a more effecient way to store a time value than using the DateTime column? I will need to convert it to a DateTime value in the SELECT query. Serious answers please. :suss:

                  Be nice to your kids. They'll choose your nursing home.
                  My Articles   Developer's Best Friend

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  I agree with the others, except when the application would fit the following description: - a lot of fields are time values, so storing them in a compact format will be significant to DB size; - the time resolution and range required are such that a small integer could do, say 1-minute resolution and a 2-day range (to cope with midnight shifts), would fit in a 16-bit int; - your DB queries are known in advance and don't require complex datetime calculations. If there is start time and end time, I would consider storing begin time and duration instead. If the above matches pretty well, then you're set for a smaller DB, and no installation, as the JET engine is always present AFAIK. OTOH if the above feel like restrictions, if there is too much uncertainty about how the requirements will evolve, if you want the comfort of full T-SQL, ... then by all means use a real DB and pay the price. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                  R 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    I agree with the others, except when the application would fit the following description: - a lot of fields are time values, so storing them in a compact format will be significant to DB size; - the time resolution and range required are such that a small integer could do, say 1-minute resolution and a 2-day range (to cope with midnight shifts), would fit in a 16-bit int; - your DB queries are known in advance and don't require complex datetime calculations. If there is start time and end time, I would consider storing begin time and duration instead. If the above matches pretty well, then you're set for a smaller DB, and no installation, as the JET engine is always present AFAIK. OTOH if the above feel like restrictions, if there is too much uncertainty about how the requirements will evolve, if you want the comfort of full T-SQL, ... then by all means use a real DB and pay the price. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                    Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                    R Offline
                    R Offline
                    Richard Blythe
                    wrote on last edited by
                    #9

                    Luc Pattyn wrote:

                    then by all means use a real DB and pay the price.

                    I would love to use SQL Server Express but the software is being deployed with CD-ROM using InstallShield 2010 express edition. This edition cannot install SQL Server silently. (Which would be a must) At this point I can't justify the $900 upgrade cost on InstallShield so Access seems to be my best bet. :sigh:

                    Be nice to your kids. They'll choose your nursing home.
                    My Articles   Developer's Best Friend

                    1 Reply Last reply
                    0
                    • R Richard Blythe

                      Lately I've been working an C# app that stores values in an Access db. One of the fields stores a time value. (7:30 PM) Is there a more effecient way to store a time value than using the DateTime column? I will need to convert it to a DateTime value in the SELECT query. Serious answers please. :suss:

                      Be nice to your kids. They'll choose your nursing home.
                      My Articles   Developer's Best Friend

                      B Offline
                      B Offline
                      Bernhard Hiller
                      wrote on last edited by
                      #10

                      I guess the problem here is not the field type in Access - in almost all cases it must be DateTime - but the user interface. Make sure you can convert a user input like "7:30 PM" correctly into a DateTime value. And that you format values returned from the database in a way the user wants to see them. For the communication with the database, you must use a parameterized query when you want to send DateTime values from your application to the database - be certain to add the DateTime values as DateTime values, and do not convert them to strings when adding them!

                      1 Reply Last reply
                      0
                      • R Richard Blythe

                        Lately I've been working an C# app that stores values in an Access db. One of the fields stores a time value. (7:30 PM) Is there a more effecient way to store a time value than using the DateTime column? I will need to convert it to a DateTime value in the SELECT query. Serious answers please. :suss:

                        Be nice to your kids. They'll choose your nursing home.
                        My Articles   Developer's Best Friend

                        C Offline
                        C Offline
                        Corporal Agarn
                        wrote on last edited by
                        #11

                        We have saved the 24 hr time in a text field as HH:MM That being said you need to look at what overhead is needed to convert it to a true time. By the way Microsoft Access and serious do not go together. :)

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups