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. Select records between day, time 05:00:00 and day+1 until time 05:00:00

Select records between day, time 05:00:00 and day+1 until time 05:00:00

Scheduled Pinned Locked Moved Database
help
18 Posts 8 Posters 0 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.
  • L Lost User

    What datatype is time? I'd recommend putting it in the DATE_CREATED column, where it belongs.

    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

    A Offline
    A Offline
    Ambertje
    wrote on last edited by
    #7

    nvarchar

    L 2 Replies Last reply
    0
    • Richard DeemingR Richard Deeming

      As others have said, the time should be part of the DATE_CREATED column. However, it's still possible to get what you need:

      WHERE
      (DATE_CREATED = '20140902' And Convert(time, TIME_CREATED) >= '05:00:00')
      Or
      (DATE_CREATED = '20140903' And Convert(time, TIME_CREATED) <= '05:00:00')


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      A Offline
      A Offline
      Ambertje
      wrote on last edited by
      #8

      Thank you so much for the help, my query is working fine now.

      1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        As others have said, the time should be part of the DATE_CREATED column. However, it's still possible to get what you need:

        WHERE
        (DATE_CREATED = '20140902' And Convert(time, TIME_CREATED) >= '05:00:00')
        Or
        (DATE_CREATED = '20140903' And Convert(time, TIME_CREATED) <= '05:00:00')


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

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

        That is great! I get started down a path and do not think outside of that. :~

        1 Reply Last reply
        0
        • A Ambertje

          nvarchar

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

          Why are you using nvarchar instead of DateTime?

          1 Reply Last reply
          0
          • A Ambertje

            nvarchar

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

            Yes, kinda predictable. It's a bad idea to do so, and should be fixed. The time you are saving is a culture-specific format, it is a text, something the computer does not calculate with. A DateTime in a computer is a floating point. The integer-part counts the days passed since the epoch (start of counting of days, often 1/1/1900), the decimal part represents the time, in ticks. They are not two separate facts - and should be modelled as a single field, of the DateTime-datatype. The computer can easily calculate with those. Breaking the date and time into separate fields is as usefull as using a separate field for the day, month, year, hour, minute and second. If they represent a single atomic fact, than that is how it should be modelled.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

            J C 2 Replies Last reply
            0
            • L Lost User

              Yes, kinda predictable. It's a bad idea to do so, and should be fixed. The time you are saving is a culture-specific format, it is a text, something the computer does not calculate with. A DateTime in a computer is a floating point. The integer-part counts the days passed since the epoch (start of counting of days, often 1/1/1900), the decimal part represents the time, in ticks. They are not two separate facts - and should be modelled as a single field, of the DateTime-datatype. The computer can easily calculate with those. Breaking the date and time into separate fields is as usefull as using a separate field for the day, month, year, hour, minute and second. If they represent a single atomic fact, than that is how it should be modelled.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

              J Offline
              J Offline
              Jorgen Andersson
              wrote on last edited by
              #12

              It's interesting that the Date type in Oracle while handled as a single entity but is stored internally as seven bytes. One byte each for year, month, day, hour minute, second and fraction of a second. It's a space waster, but oh so fast to calculate with. Timestamp on the other hand is stored as a floating point to save space.

              Wrong is evil and must be defeated. - Jeff Ello[^]

              L 1 Reply Last reply
              0
              • J Jorgen Andersson

                It's interesting that the Date type in Oracle while handled as a single entity but is stored internally as seven bytes. One byte each for year, month, day, hour minute, second and fraction of a second. It's a space waster, but oh so fast to calculate with. Timestamp on the other hand is stored as a floating point to save space.

                Wrong is evil and must be defeated. - Jeff Ello[^]

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

                Internally, yes, if the engine expects it. But still no way to model a database.

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                J 1 Reply Last reply
                0
                • L Lost User

                  Internally, yes, if the engine expects it. But still no way to model a database.

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                  J Offline
                  J Offline
                  Jorgen Andersson
                  wrote on last edited by
                  #14

                  Indeed.

                  Wrong is evil and must be defeated. - Jeff Ello[^]

                  1 Reply Last reply
                  0
                  • L Lost User

                    Yes, kinda predictable. It's a bad idea to do so, and should be fixed. The time you are saving is a culture-specific format, it is a text, something the computer does not calculate with. A DateTime in a computer is a floating point. The integer-part counts the days passed since the epoch (start of counting of days, often 1/1/1900), the decimal part represents the time, in ticks. They are not two separate facts - and should be modelled as a single field, of the DateTime-datatype. The computer can easily calculate with those. Breaking the date and time into separate fields is as usefull as using a separate field for the day, month, year, hour, minute and second. If they represent a single atomic fact, than that is how it should be modelled.

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

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

                    If date and time should not be keep separate, why did MS create data formats DATE and TIME? :-D

                    Richard DeemingR 1 Reply Last reply
                    0
                    • C Corporal Agarn

                      If date and time should not be keep separate, why did MS create data formats DATE and TIME? :-D

                      Richard DeemingR Offline
                      Richard DeemingR Offline
                      Richard Deeming
                      wrote on last edited by
                      #16

                      Because there are times when you do need to store just a date or just a time. The OP's example just isn't one of them. :)


                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                      1 Reply Last reply
                      0
                      • Richard DeemingR Richard Deeming

                        As others have said, the time should be part of the DATE_CREATED column. However, it's still possible to get what you need:

                        WHERE
                        (DATE_CREATED = '20140902' And Convert(time, TIME_CREATED) >= '05:00:00')
                        Or
                        (DATE_CREATED = '20140903' And Convert(time, TIME_CREATED) <= '05:00:00')


                        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                        S Offline
                        S Offline
                        sai sruthi
                        wrote on last edited by
                        #17

                        convert function is not working in access

                        1 Reply Last reply
                        0
                        • A Ambertje

                          Hello everyone, Can someone help me select rows between 2 dates en between 2 times. I need to select all records from 02/09/2014 starting from time 05:00:00 until the next day time until 05:00 If I do it like this then it wont work, no records shows:

                          SELECT TOP 10000 *
                          FROM Staging.[dbo].AD
                          WHERE DATE_CREATED BETWEEN '02/09/2014' and '03/09/2014'
                          AND Convert(Time,TIME_CREATED) between '05:00:00' AND '05:00:00'

                          It should be something like this: Between DATE_CREATED 02/09/2014, TIME_CREATED 05:00:00 and DATE_CREATED 03/09/2014, TIME_CREATED 05:00:00 Kind regards, Ambertje

                          C Offline
                          C Offline
                          challa naresh kumar reddy
                          wrote on last edited by
                          #18

                          select * from Staging.[dbo].AD where DATE_CREATED between '2013-03-08 05:00:00' and '2013-03-09 05:00:00' -- I hope i will help u...

                          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