How to query DATETIME field using only date in SQL Server?











up vote
53
down vote

favorite
19












Simple question but i can't manage to solve it yet...



I have a table TEST with a DATETIME field, like this :



ID NAME DATE
1 TESTING 2014-03-19 20:05:20.000


What i need is the query below returns this row and every rows with date = 03/19/2014, no matter what time is :



select * from test where date = '03/19/2014';


But it returns no rows. Only way to work is specifying also the time :



select * from test where date = '03/19/2014 20:03:02.000';


Thanks in advance !










share|improve this question




























    up vote
    53
    down vote

    favorite
    19












    Simple question but i can't manage to solve it yet...



    I have a table TEST with a DATETIME field, like this :



    ID NAME DATE
    1 TESTING 2014-03-19 20:05:20.000


    What i need is the query below returns this row and every rows with date = 03/19/2014, no matter what time is :



    select * from test where date = '03/19/2014';


    But it returns no rows. Only way to work is specifying also the time :



    select * from test where date = '03/19/2014 20:03:02.000';


    Thanks in advance !










    share|improve this question


























      up vote
      53
      down vote

      favorite
      19









      up vote
      53
      down vote

      favorite
      19






      19





      Simple question but i can't manage to solve it yet...



      I have a table TEST with a DATETIME field, like this :



      ID NAME DATE
      1 TESTING 2014-03-19 20:05:20.000


      What i need is the query below returns this row and every rows with date = 03/19/2014, no matter what time is :



      select * from test where date = '03/19/2014';


      But it returns no rows. Only way to work is specifying also the time :



      select * from test where date = '03/19/2014 20:03:02.000';


      Thanks in advance !










      share|improve this question















      Simple question but i can't manage to solve it yet...



      I have a table TEST with a DATETIME field, like this :



      ID NAME DATE
      1 TESTING 2014-03-19 20:05:20.000


      What i need is the query below returns this row and every rows with date = 03/19/2014, no matter what time is :



      select * from test where date = '03/19/2014';


      But it returns no rows. Only way to work is specifying also the time :



      select * from test where date = '03/19/2014 20:03:02.000';


      Thanks in advance !







      sql-server datetime






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 19 '14 at 13:16









      Charles Bretana

      111k18120197




      111k18120197










      asked Mar 19 '14 at 13:10









      delphirules

      1,96992549




      1,96992549
























          16 Answers
          16






          active

          oldest

          votes

















          up vote
          76
          down vote



          accepted










          use range, or DateDiff function



           select * from test 
          where date between '03/19/2014' and '03/19/2014 23:59:59'


          or



           select * from test 
          where datediff(day, date, '03/19/2014') = 0


          Other options are:




          1. If you have control over the database schema, and you don't need the
            time data, take it out.


          2. or, if you must keep it, add a computed column attribute that has the time portion of the date value stripped off...



          Alter table Test
          Add DateOnly As
          DateAdd(day, datediff(day, 0, date), 0)



          or, in more recent versions of SQL Server...



          Alter table Test
          Add DateOnly As
          Cast(DateAdd(day, datediff(day, 0, date), 0) as Date)



          then, you can write your query as simply:



          select * from test 
          where DateOnly = '03/19/2014'





          share|improve this answer























          • Ok, this works, but i was wondering if is there any easier way.
            – delphirules
            Mar 19 '14 at 13:31










          • Well, the only other easier way is not to put time data into the database in the first place... or create a computed attribute that strips off the time portion and use it... I added both options to my answer.
            – Charles Bretana
            Mar 19 '14 at 14:48










          • I was concerned that the DATEDIFF method would return true (undesirably) for dates like 4/19/2014 or 3/19/2015, as the 'day' portion of those dates is the same (and I had seen reports elsewhere that it would act in this way), but I tested it against a database, and it seems to work correctly.
            – mono código
            Jan 5 '16 at 19:29










          • Yes, because the DateDiff() function, in all its variants, computes and returns the number of date boundaries that must be crossed to get frlom one date to the other. This is why DateDiff(day, '1Jan2016', '31Dec2017 23:259:59') and DateDiff(day, '31Dec2016 23:259:59', '1Jan2017 ') both return 1.
            – Charles Bretana
            Jan 25 '17 at 15:49




















          up vote
          35
          down vote













          Simple answer;



          select * from test where cast ([date] as date) = '03/19/2014';





          share|improve this answer






























            up vote
            16
            down vote













            I am using MySQL 5.6 and there is a DATE function to extract only the date part from date time. So the simple solution to the question is -



             select * from test where DATE(date) = '2014-03-19';


            http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html






            share|improve this answer



















            • 1




              works for me, better than modifying the table structure etc....
              – self.name
              Dec 21 '17 at 21:15










            • This was the easiest answer, even works with Informix.
              – Himarm
              Apr 25 at 13:55


















            up vote
            2
            down vote













            Try this



             select * from test where Convert(varchar, date,111)= '03/19/2014'





            share|improve this answer




























              up vote
              2
              down vote













              select * from test 
              where date between '03/19/2014' and '03/19/2014 23:59:59'


              This is a realy bad answer. For two reasons.



              1.
              What happens with times like 23.59.59.700 etc.
              There are times larger than 23:59:59 and the next day.



              2.
              The behaviour depends on the datatype.
              The query behaves differently for datetime/date/datetime2 types.



              Testing with 23:59:59.999 makes it even worse because depending on the datetype you get different roundings.



              select convert (varchar(40),convert(date      , '2014-03-19 23:59:59.999'))
              select convert (varchar(40),convert(datetime , '2014-03-19 23:59:59.999'))
              select convert (varchar(40),convert(datetime2 , '2014-03-19 23:59:59.999'))


              -- For date the value is 'chopped'.
              -- For datetime the value is rounded up to the next date. (Nearest value).
              -- For datetime2 the value is precise.






              share|improve this answer




























                up vote
                1
                down vote













                you can try this



                select * from test where DATEADD(dd, 0, DATEDIFF(dd, 0, date)) = '03/19/2014';





                share|improve this answer



















                • 1




                  Thank you, but i think the simpler solution would be a comparison with time, just like the previous solution.
                  – delphirules
                  Mar 19 '14 at 13:46




















                up vote
                1
                down vote













                This works for me for MS SQL server:



                select * from test
                where
                year(date) = 2015
                and month(date) = 10
                and day(date)= 28 ;





                share|improve this answer






























                  up vote
                  0
                  down vote













                  You can use this approach which truncates the time part:



                  select * from test
                  where convert(datetime,'03/19/2014',102) = DATEADD(dd, DATEDIFF(dd, 0, date), 0)





                  share|improve this answer




























                    up vote
                    0
                    down vote













                    -- Reverse the date format
                    -- this false:
                    select * from test where date = '28/10/2015'
                    -- this true:
                    select * from test where date = '2015/10/28'





                    share|improve this answer























                    • Please add some explanation to your answer!
                      – ρss
                      Nov 6 '15 at 14:16










                    • This doesn't work because '2015/10/28 00:00.001' is different from '2015/10/28'
                      – PedroC88
                      Jan 5 '16 at 21:14


















                    up vote
                    0
                    down vote













                    Test this query.



                    SELECT *,DATE(chat_reg_date) AS is_date,TIME(chat_reg_time) AS is_time FROM chat WHERE chat_inbox_key='$chat_key' 
                    ORDER BY is_date DESC, is_time DESC





                    share|improve this answer




























                      up vote
                      0
                      down vote













                      Simply use this in your WHERE clause.



                      The "SubmitDate" portion below is the column name, so insert your own.



                      This will return only the "Year" portion of the results, omitting the mins etc.



                      Where datepart(year, SubmitDate) = '2017'





                      share|improve this answer






























                        up vote
                        0
                        down vote













                        select *, cast ([col1] as date) <name of the column> from test where date = 'mm/dd/yyyy'


                        "col1" is name of the column with date and time

                        <name of the column> here you can change name as desired






                        share|improve this answer






























                          up vote
                          0
                          down vote













                          select *
                          from invoice
                          where TRUNC(created_date) <=TRUNC(to_date('04-MAR-18 15:00:00','dd-mon-yy hh24:mi:ss'));





                          share|improve this answer






























                            up vote
                            0
                            down vote













                            There is a problem with dates and languages and the way to avoid it is asking for dates with this format YYYYMMDD.



                            This way below should be the fastest according to the link below. I checked in SQL Server 2012 and I agree with the link.



                            select * from test where date >= '20141903' AND date < DATEADD(DAY, 1, '20141903');



                            • Bad habits to kick : mis-handling date / range queries






                            share|improve this answer






























                              up vote
                              -1
                              down vote













                              select * from invoice where TRANS_DATE_D>= to_date  ('20170831115959','YYYYMMDDHH24MISS')
                              and TRANS_DATE_D<= to_date ('20171031115959','YYYYMMDDHH24MISS');





                              share|improve this answer























                              • I think this is Oracle syntax, do not work at sql server
                                – ceinmart
                                Mar 14 at 13:53


















                              up vote
                              -2
                              down vote













                              SELECT * FROM test where DATEPART(year,[TIMESTAMP]) = '2018'  and  DATEPART(day,[TIMESTAMP]) = '16' and  DATEPART(month,[TIMESTAMP]) = '11'





                              share|improve this answer










                              New contributor




                              Kalidas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                              Check out our Code of Conduct.


















                                Your Answer






                                StackExchange.ifUsing("editor", function () {
                                StackExchange.using("externalEditor", function () {
                                StackExchange.using("snippets", function () {
                                StackExchange.snippets.init();
                                });
                                });
                                }, "code-snippets");

                                StackExchange.ready(function() {
                                var channelOptions = {
                                tags: "".split(" "),
                                id: "1"
                                };
                                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                                StackExchange.using("externalEditor", function() {
                                // Have to fire editor after snippets, if snippets enabled
                                if (StackExchange.settings.snippets.snippetsEnabled) {
                                StackExchange.using("snippets", function() {
                                createEditor();
                                });
                                }
                                else {
                                createEditor();
                                }
                                });

                                function createEditor() {
                                StackExchange.prepareEditor({
                                heartbeatType: 'answer',
                                convertImagesToLinks: true,
                                noModals: true,
                                showLowRepImageUploadWarning: true,
                                reputationToPostImages: 10,
                                bindNavPrevention: true,
                                postfix: "",
                                imageUploader: {
                                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                                allowUrls: true
                                },
                                onDemand: true,
                                discardSelector: ".discard-answer"
                                ,immediatelyShowMarkdownHelp:true
                                });


                                }
                                });














                                 

                                draft saved


                                draft discarded


















                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22506930%2fhow-to-query-datetime-field-using-only-date-in-sql-server%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown

























                                16 Answers
                                16






                                active

                                oldest

                                votes








                                16 Answers
                                16






                                active

                                oldest

                                votes









                                active

                                oldest

                                votes






                                active

                                oldest

                                votes








                                up vote
                                76
                                down vote



                                accepted










                                use range, or DateDiff function



                                 select * from test 
                                where date between '03/19/2014' and '03/19/2014 23:59:59'


                                or



                                 select * from test 
                                where datediff(day, date, '03/19/2014') = 0


                                Other options are:




                                1. If you have control over the database schema, and you don't need the
                                  time data, take it out.


                                2. or, if you must keep it, add a computed column attribute that has the time portion of the date value stripped off...



                                Alter table Test
                                Add DateOnly As
                                DateAdd(day, datediff(day, 0, date), 0)



                                or, in more recent versions of SQL Server...



                                Alter table Test
                                Add DateOnly As
                                Cast(DateAdd(day, datediff(day, 0, date), 0) as Date)



                                then, you can write your query as simply:



                                select * from test 
                                where DateOnly = '03/19/2014'





                                share|improve this answer























                                • Ok, this works, but i was wondering if is there any easier way.
                                  – delphirules
                                  Mar 19 '14 at 13:31










                                • Well, the only other easier way is not to put time data into the database in the first place... or create a computed attribute that strips off the time portion and use it... I added both options to my answer.
                                  – Charles Bretana
                                  Mar 19 '14 at 14:48










                                • I was concerned that the DATEDIFF method would return true (undesirably) for dates like 4/19/2014 or 3/19/2015, as the 'day' portion of those dates is the same (and I had seen reports elsewhere that it would act in this way), but I tested it against a database, and it seems to work correctly.
                                  – mono código
                                  Jan 5 '16 at 19:29










                                • Yes, because the DateDiff() function, in all its variants, computes and returns the number of date boundaries that must be crossed to get frlom one date to the other. This is why DateDiff(day, '1Jan2016', '31Dec2017 23:259:59') and DateDiff(day, '31Dec2016 23:259:59', '1Jan2017 ') both return 1.
                                  – Charles Bretana
                                  Jan 25 '17 at 15:49

















                                up vote
                                76
                                down vote



                                accepted










                                use range, or DateDiff function



                                 select * from test 
                                where date between '03/19/2014' and '03/19/2014 23:59:59'


                                or



                                 select * from test 
                                where datediff(day, date, '03/19/2014') = 0


                                Other options are:




                                1. If you have control over the database schema, and you don't need the
                                  time data, take it out.


                                2. or, if you must keep it, add a computed column attribute that has the time portion of the date value stripped off...



                                Alter table Test
                                Add DateOnly As
                                DateAdd(day, datediff(day, 0, date), 0)



                                or, in more recent versions of SQL Server...



                                Alter table Test
                                Add DateOnly As
                                Cast(DateAdd(day, datediff(day, 0, date), 0) as Date)



                                then, you can write your query as simply:



                                select * from test 
                                where DateOnly = '03/19/2014'





                                share|improve this answer























                                • Ok, this works, but i was wondering if is there any easier way.
                                  – delphirules
                                  Mar 19 '14 at 13:31










                                • Well, the only other easier way is not to put time data into the database in the first place... or create a computed attribute that strips off the time portion and use it... I added both options to my answer.
                                  – Charles Bretana
                                  Mar 19 '14 at 14:48










                                • I was concerned that the DATEDIFF method would return true (undesirably) for dates like 4/19/2014 or 3/19/2015, as the 'day' portion of those dates is the same (and I had seen reports elsewhere that it would act in this way), but I tested it against a database, and it seems to work correctly.
                                  – mono código
                                  Jan 5 '16 at 19:29










                                • Yes, because the DateDiff() function, in all its variants, computes and returns the number of date boundaries that must be crossed to get frlom one date to the other. This is why DateDiff(day, '1Jan2016', '31Dec2017 23:259:59') and DateDiff(day, '31Dec2016 23:259:59', '1Jan2017 ') both return 1.
                                  – Charles Bretana
                                  Jan 25 '17 at 15:49















                                up vote
                                76
                                down vote



                                accepted







                                up vote
                                76
                                down vote



                                accepted






                                use range, or DateDiff function



                                 select * from test 
                                where date between '03/19/2014' and '03/19/2014 23:59:59'


                                or



                                 select * from test 
                                where datediff(day, date, '03/19/2014') = 0


                                Other options are:




                                1. If you have control over the database schema, and you don't need the
                                  time data, take it out.


                                2. or, if you must keep it, add a computed column attribute that has the time portion of the date value stripped off...



                                Alter table Test
                                Add DateOnly As
                                DateAdd(day, datediff(day, 0, date), 0)



                                or, in more recent versions of SQL Server...



                                Alter table Test
                                Add DateOnly As
                                Cast(DateAdd(day, datediff(day, 0, date), 0) as Date)



                                then, you can write your query as simply:



                                select * from test 
                                where DateOnly = '03/19/2014'





                                share|improve this answer














                                use range, or DateDiff function



                                 select * from test 
                                where date between '03/19/2014' and '03/19/2014 23:59:59'


                                or



                                 select * from test 
                                where datediff(day, date, '03/19/2014') = 0


                                Other options are:




                                1. If you have control over the database schema, and you don't need the
                                  time data, take it out.


                                2. or, if you must keep it, add a computed column attribute that has the time portion of the date value stripped off...



                                Alter table Test
                                Add DateOnly As
                                DateAdd(day, datediff(day, 0, date), 0)



                                or, in more recent versions of SQL Server...



                                Alter table Test
                                Add DateOnly As
                                Cast(DateAdd(day, datediff(day, 0, date), 0) as Date)



                                then, you can write your query as simply:



                                select * from test 
                                where DateOnly = '03/19/2014'






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Sep 11 '14 at 12:42

























                                answered Mar 19 '14 at 13:14









                                Charles Bretana

                                111k18120197




                                111k18120197












                                • Ok, this works, but i was wondering if is there any easier way.
                                  – delphirules
                                  Mar 19 '14 at 13:31










                                • Well, the only other easier way is not to put time data into the database in the first place... or create a computed attribute that strips off the time portion and use it... I added both options to my answer.
                                  – Charles Bretana
                                  Mar 19 '14 at 14:48










                                • I was concerned that the DATEDIFF method would return true (undesirably) for dates like 4/19/2014 or 3/19/2015, as the 'day' portion of those dates is the same (and I had seen reports elsewhere that it would act in this way), but I tested it against a database, and it seems to work correctly.
                                  – mono código
                                  Jan 5 '16 at 19:29










                                • Yes, because the DateDiff() function, in all its variants, computes and returns the number of date boundaries that must be crossed to get frlom one date to the other. This is why DateDiff(day, '1Jan2016', '31Dec2017 23:259:59') and DateDiff(day, '31Dec2016 23:259:59', '1Jan2017 ') both return 1.
                                  – Charles Bretana
                                  Jan 25 '17 at 15:49




















                                • Ok, this works, but i was wondering if is there any easier way.
                                  – delphirules
                                  Mar 19 '14 at 13:31










                                • Well, the only other easier way is not to put time data into the database in the first place... or create a computed attribute that strips off the time portion and use it... I added both options to my answer.
                                  – Charles Bretana
                                  Mar 19 '14 at 14:48










                                • I was concerned that the DATEDIFF method would return true (undesirably) for dates like 4/19/2014 or 3/19/2015, as the 'day' portion of those dates is the same (and I had seen reports elsewhere that it would act in this way), but I tested it against a database, and it seems to work correctly.
                                  – mono código
                                  Jan 5 '16 at 19:29










                                • Yes, because the DateDiff() function, in all its variants, computes and returns the number of date boundaries that must be crossed to get frlom one date to the other. This is why DateDiff(day, '1Jan2016', '31Dec2017 23:259:59') and DateDiff(day, '31Dec2016 23:259:59', '1Jan2017 ') both return 1.
                                  – Charles Bretana
                                  Jan 25 '17 at 15:49


















                                Ok, this works, but i was wondering if is there any easier way.
                                – delphirules
                                Mar 19 '14 at 13:31




                                Ok, this works, but i was wondering if is there any easier way.
                                – delphirules
                                Mar 19 '14 at 13:31












                                Well, the only other easier way is not to put time data into the database in the first place... or create a computed attribute that strips off the time portion and use it... I added both options to my answer.
                                – Charles Bretana
                                Mar 19 '14 at 14:48




                                Well, the only other easier way is not to put time data into the database in the first place... or create a computed attribute that strips off the time portion and use it... I added both options to my answer.
                                – Charles Bretana
                                Mar 19 '14 at 14:48












                                I was concerned that the DATEDIFF method would return true (undesirably) for dates like 4/19/2014 or 3/19/2015, as the 'day' portion of those dates is the same (and I had seen reports elsewhere that it would act in this way), but I tested it against a database, and it seems to work correctly.
                                – mono código
                                Jan 5 '16 at 19:29




                                I was concerned that the DATEDIFF method would return true (undesirably) for dates like 4/19/2014 or 3/19/2015, as the 'day' portion of those dates is the same (and I had seen reports elsewhere that it would act in this way), but I tested it against a database, and it seems to work correctly.
                                – mono código
                                Jan 5 '16 at 19:29












                                Yes, because the DateDiff() function, in all its variants, computes and returns the number of date boundaries that must be crossed to get frlom one date to the other. This is why DateDiff(day, '1Jan2016', '31Dec2017 23:259:59') and DateDiff(day, '31Dec2016 23:259:59', '1Jan2017 ') both return 1.
                                – Charles Bretana
                                Jan 25 '17 at 15:49






                                Yes, because the DateDiff() function, in all its variants, computes and returns the number of date boundaries that must be crossed to get frlom one date to the other. This is why DateDiff(day, '1Jan2016', '31Dec2017 23:259:59') and DateDiff(day, '31Dec2016 23:259:59', '1Jan2017 ') both return 1.
                                – Charles Bretana
                                Jan 25 '17 at 15:49














                                up vote
                                35
                                down vote













                                Simple answer;



                                select * from test where cast ([date] as date) = '03/19/2014';





                                share|improve this answer



























                                  up vote
                                  35
                                  down vote













                                  Simple answer;



                                  select * from test where cast ([date] as date) = '03/19/2014';





                                  share|improve this answer

























                                    up vote
                                    35
                                    down vote










                                    up vote
                                    35
                                    down vote









                                    Simple answer;



                                    select * from test where cast ([date] as date) = '03/19/2014';





                                    share|improve this answer














                                    Simple answer;



                                    select * from test where cast ([date] as date) = '03/19/2014';






                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Jan 16 '15 at 18:19









                                    dario

                                    4,405122229




                                    4,405122229










                                    answered Jan 16 '15 at 17:55









                                    kabcha

                                    35132




                                    35132






















                                        up vote
                                        16
                                        down vote













                                        I am using MySQL 5.6 and there is a DATE function to extract only the date part from date time. So the simple solution to the question is -



                                         select * from test where DATE(date) = '2014-03-19';


                                        http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html






                                        share|improve this answer



















                                        • 1




                                          works for me, better than modifying the table structure etc....
                                          – self.name
                                          Dec 21 '17 at 21:15










                                        • This was the easiest answer, even works with Informix.
                                          – Himarm
                                          Apr 25 at 13:55















                                        up vote
                                        16
                                        down vote













                                        I am using MySQL 5.6 and there is a DATE function to extract only the date part from date time. So the simple solution to the question is -



                                         select * from test where DATE(date) = '2014-03-19';


                                        http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html






                                        share|improve this answer



















                                        • 1




                                          works for me, better than modifying the table structure etc....
                                          – self.name
                                          Dec 21 '17 at 21:15










                                        • This was the easiest answer, even works with Informix.
                                          – Himarm
                                          Apr 25 at 13:55













                                        up vote
                                        16
                                        down vote










                                        up vote
                                        16
                                        down vote









                                        I am using MySQL 5.6 and there is a DATE function to extract only the date part from date time. So the simple solution to the question is -



                                         select * from test where DATE(date) = '2014-03-19';


                                        http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html






                                        share|improve this answer














                                        I am using MySQL 5.6 and there is a DATE function to extract only the date part from date time. So the simple solution to the question is -



                                         select * from test where DATE(date) = '2014-03-19';


                                        http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Jul 1 '15 at 7:06

























                                        answered Jun 8 '15 at 10:46









                                        Goku__

                                        461822




                                        461822








                                        • 1




                                          works for me, better than modifying the table structure etc....
                                          – self.name
                                          Dec 21 '17 at 21:15










                                        • This was the easiest answer, even works with Informix.
                                          – Himarm
                                          Apr 25 at 13:55














                                        • 1




                                          works for me, better than modifying the table structure etc....
                                          – self.name
                                          Dec 21 '17 at 21:15










                                        • This was the easiest answer, even works with Informix.
                                          – Himarm
                                          Apr 25 at 13:55








                                        1




                                        1




                                        works for me, better than modifying the table structure etc....
                                        – self.name
                                        Dec 21 '17 at 21:15




                                        works for me, better than modifying the table structure etc....
                                        – self.name
                                        Dec 21 '17 at 21:15












                                        This was the easiest answer, even works with Informix.
                                        – Himarm
                                        Apr 25 at 13:55




                                        This was the easiest answer, even works with Informix.
                                        – Himarm
                                        Apr 25 at 13:55










                                        up vote
                                        2
                                        down vote













                                        Try this



                                         select * from test where Convert(varchar, date,111)= '03/19/2014'





                                        share|improve this answer

























                                          up vote
                                          2
                                          down vote













                                          Try this



                                           select * from test where Convert(varchar, date,111)= '03/19/2014'





                                          share|improve this answer























                                            up vote
                                            2
                                            down vote










                                            up vote
                                            2
                                            down vote









                                            Try this



                                             select * from test where Convert(varchar, date,111)= '03/19/2014'





                                            share|improve this answer












                                            Try this



                                             select * from test where Convert(varchar, date,111)= '03/19/2014'






                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Mar 19 '14 at 13:13









                                            Amit

                                            13.3k63459




                                            13.3k63459






















                                                up vote
                                                2
                                                down vote













                                                select * from test 
                                                where date between '03/19/2014' and '03/19/2014 23:59:59'


                                                This is a realy bad answer. For two reasons.



                                                1.
                                                What happens with times like 23.59.59.700 etc.
                                                There are times larger than 23:59:59 and the next day.



                                                2.
                                                The behaviour depends on the datatype.
                                                The query behaves differently for datetime/date/datetime2 types.



                                                Testing with 23:59:59.999 makes it even worse because depending on the datetype you get different roundings.



                                                select convert (varchar(40),convert(date      , '2014-03-19 23:59:59.999'))
                                                select convert (varchar(40),convert(datetime , '2014-03-19 23:59:59.999'))
                                                select convert (varchar(40),convert(datetime2 , '2014-03-19 23:59:59.999'))


                                                -- For date the value is 'chopped'.
                                                -- For datetime the value is rounded up to the next date. (Nearest value).
                                                -- For datetime2 the value is precise.






                                                share|improve this answer

























                                                  up vote
                                                  2
                                                  down vote













                                                  select * from test 
                                                  where date between '03/19/2014' and '03/19/2014 23:59:59'


                                                  This is a realy bad answer. For two reasons.



                                                  1.
                                                  What happens with times like 23.59.59.700 etc.
                                                  There are times larger than 23:59:59 and the next day.



                                                  2.
                                                  The behaviour depends on the datatype.
                                                  The query behaves differently for datetime/date/datetime2 types.



                                                  Testing with 23:59:59.999 makes it even worse because depending on the datetype you get different roundings.



                                                  select convert (varchar(40),convert(date      , '2014-03-19 23:59:59.999'))
                                                  select convert (varchar(40),convert(datetime , '2014-03-19 23:59:59.999'))
                                                  select convert (varchar(40),convert(datetime2 , '2014-03-19 23:59:59.999'))


                                                  -- For date the value is 'chopped'.
                                                  -- For datetime the value is rounded up to the next date. (Nearest value).
                                                  -- For datetime2 the value is precise.






                                                  share|improve this answer























                                                    up vote
                                                    2
                                                    down vote










                                                    up vote
                                                    2
                                                    down vote









                                                    select * from test 
                                                    where date between '03/19/2014' and '03/19/2014 23:59:59'


                                                    This is a realy bad answer. For two reasons.



                                                    1.
                                                    What happens with times like 23.59.59.700 etc.
                                                    There are times larger than 23:59:59 and the next day.



                                                    2.
                                                    The behaviour depends on the datatype.
                                                    The query behaves differently for datetime/date/datetime2 types.



                                                    Testing with 23:59:59.999 makes it even worse because depending on the datetype you get different roundings.



                                                    select convert (varchar(40),convert(date      , '2014-03-19 23:59:59.999'))
                                                    select convert (varchar(40),convert(datetime , '2014-03-19 23:59:59.999'))
                                                    select convert (varchar(40),convert(datetime2 , '2014-03-19 23:59:59.999'))


                                                    -- For date the value is 'chopped'.
                                                    -- For datetime the value is rounded up to the next date. (Nearest value).
                                                    -- For datetime2 the value is precise.






                                                    share|improve this answer












                                                    select * from test 
                                                    where date between '03/19/2014' and '03/19/2014 23:59:59'


                                                    This is a realy bad answer. For two reasons.



                                                    1.
                                                    What happens with times like 23.59.59.700 etc.
                                                    There are times larger than 23:59:59 and the next day.



                                                    2.
                                                    The behaviour depends on the datatype.
                                                    The query behaves differently for datetime/date/datetime2 types.



                                                    Testing with 23:59:59.999 makes it even worse because depending on the datetype you get different roundings.



                                                    select convert (varchar(40),convert(date      , '2014-03-19 23:59:59.999'))
                                                    select convert (varchar(40),convert(datetime , '2014-03-19 23:59:59.999'))
                                                    select convert (varchar(40),convert(datetime2 , '2014-03-19 23:59:59.999'))


                                                    -- For date the value is 'chopped'.
                                                    -- For datetime the value is rounded up to the next date. (Nearest value).
                                                    -- For datetime2 the value is precise.







                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered Mar 6 '17 at 16:42









                                                    Ben

                                                    511




                                                    511






















                                                        up vote
                                                        1
                                                        down vote













                                                        you can try this



                                                        select * from test where DATEADD(dd, 0, DATEDIFF(dd, 0, date)) = '03/19/2014';





                                                        share|improve this answer



















                                                        • 1




                                                          Thank you, but i think the simpler solution would be a comparison with time, just like the previous solution.
                                                          – delphirules
                                                          Mar 19 '14 at 13:46

















                                                        up vote
                                                        1
                                                        down vote













                                                        you can try this



                                                        select * from test where DATEADD(dd, 0, DATEDIFF(dd, 0, date)) = '03/19/2014';





                                                        share|improve this answer



















                                                        • 1




                                                          Thank you, but i think the simpler solution would be a comparison with time, just like the previous solution.
                                                          – delphirules
                                                          Mar 19 '14 at 13:46















                                                        up vote
                                                        1
                                                        down vote










                                                        up vote
                                                        1
                                                        down vote









                                                        you can try this



                                                        select * from test where DATEADD(dd, 0, DATEDIFF(dd, 0, date)) = '03/19/2014';





                                                        share|improve this answer














                                                        you can try this



                                                        select * from test where DATEADD(dd, 0, DATEDIFF(dd, 0, date)) = '03/19/2014';






                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited Mar 19 '14 at 14:11

























                                                        answered Mar 19 '14 at 13:45









                                                        HeLL

                                                        1336




                                                        1336








                                                        • 1




                                                          Thank you, but i think the simpler solution would be a comparison with time, just like the previous solution.
                                                          – delphirules
                                                          Mar 19 '14 at 13:46
















                                                        • 1




                                                          Thank you, but i think the simpler solution would be a comparison with time, just like the previous solution.
                                                          – delphirules
                                                          Mar 19 '14 at 13:46










                                                        1




                                                        1




                                                        Thank you, but i think the simpler solution would be a comparison with time, just like the previous solution.
                                                        – delphirules
                                                        Mar 19 '14 at 13:46






                                                        Thank you, but i think the simpler solution would be a comparison with time, just like the previous solution.
                                                        – delphirules
                                                        Mar 19 '14 at 13:46












                                                        up vote
                                                        1
                                                        down vote













                                                        This works for me for MS SQL server:



                                                        select * from test
                                                        where
                                                        year(date) = 2015
                                                        and month(date) = 10
                                                        and day(date)= 28 ;





                                                        share|improve this answer



























                                                          up vote
                                                          1
                                                          down vote













                                                          This works for me for MS SQL server:



                                                          select * from test
                                                          where
                                                          year(date) = 2015
                                                          and month(date) = 10
                                                          and day(date)= 28 ;





                                                          share|improve this answer

























                                                            up vote
                                                            1
                                                            down vote










                                                            up vote
                                                            1
                                                            down vote









                                                            This works for me for MS SQL server:



                                                            select * from test
                                                            where
                                                            year(date) = 2015
                                                            and month(date) = 10
                                                            and day(date)= 28 ;





                                                            share|improve this answer














                                                            This works for me for MS SQL server:



                                                            select * from test
                                                            where
                                                            year(date) = 2015
                                                            and month(date) = 10
                                                            and day(date)= 28 ;






                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited Mar 9 at 10:03









                                                            Pang

                                                            6,8021563101




                                                            6,8021563101










                                                            answered Mar 9 at 9:43









                                                            Jeroen Krah

                                                            111




                                                            111






















                                                                up vote
                                                                0
                                                                down vote













                                                                You can use this approach which truncates the time part:



                                                                select * from test
                                                                where convert(datetime,'03/19/2014',102) = DATEADD(dd, DATEDIFF(dd, 0, date), 0)





                                                                share|improve this answer

























                                                                  up vote
                                                                  0
                                                                  down vote













                                                                  You can use this approach which truncates the time part:



                                                                  select * from test
                                                                  where convert(datetime,'03/19/2014',102) = DATEADD(dd, DATEDIFF(dd, 0, date), 0)





                                                                  share|improve this answer























                                                                    up vote
                                                                    0
                                                                    down vote










                                                                    up vote
                                                                    0
                                                                    down vote









                                                                    You can use this approach which truncates the time part:



                                                                    select * from test
                                                                    where convert(datetime,'03/19/2014',102) = DATEADD(dd, DATEDIFF(dd, 0, date), 0)





                                                                    share|improve this answer












                                                                    You can use this approach which truncates the time part:



                                                                    select * from test
                                                                    where convert(datetime,'03/19/2014',102) = DATEADD(dd, DATEDIFF(dd, 0, date), 0)






                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Mar 19 '14 at 13:15









                                                                    Tim Schmelter

                                                                    357k44448705




                                                                    357k44448705






















                                                                        up vote
                                                                        0
                                                                        down vote













                                                                        -- Reverse the date format
                                                                        -- this false:
                                                                        select * from test where date = '28/10/2015'
                                                                        -- this true:
                                                                        select * from test where date = '2015/10/28'





                                                                        share|improve this answer























                                                                        • Please add some explanation to your answer!
                                                                          – ρss
                                                                          Nov 6 '15 at 14:16










                                                                        • This doesn't work because '2015/10/28 00:00.001' is different from '2015/10/28'
                                                                          – PedroC88
                                                                          Jan 5 '16 at 21:14















                                                                        up vote
                                                                        0
                                                                        down vote













                                                                        -- Reverse the date format
                                                                        -- this false:
                                                                        select * from test where date = '28/10/2015'
                                                                        -- this true:
                                                                        select * from test where date = '2015/10/28'





                                                                        share|improve this answer























                                                                        • Please add some explanation to your answer!
                                                                          – ρss
                                                                          Nov 6 '15 at 14:16










                                                                        • This doesn't work because '2015/10/28 00:00.001' is different from '2015/10/28'
                                                                          – PedroC88
                                                                          Jan 5 '16 at 21:14













                                                                        up vote
                                                                        0
                                                                        down vote










                                                                        up vote
                                                                        0
                                                                        down vote









                                                                        -- Reverse the date format
                                                                        -- this false:
                                                                        select * from test where date = '28/10/2015'
                                                                        -- this true:
                                                                        select * from test where date = '2015/10/28'





                                                                        share|improve this answer














                                                                        -- Reverse the date format
                                                                        -- this false:
                                                                        select * from test where date = '28/10/2015'
                                                                        -- this true:
                                                                        select * from test where date = '2015/10/28'






                                                                        share|improve this answer














                                                                        share|improve this answer



                                                                        share|improve this answer








                                                                        edited Nov 7 '15 at 2:41

























                                                                        answered Nov 3 '15 at 4:08









                                                                        Sherif Hamdy

                                                                        391410




                                                                        391410












                                                                        • Please add some explanation to your answer!
                                                                          – ρss
                                                                          Nov 6 '15 at 14:16










                                                                        • This doesn't work because '2015/10/28 00:00.001' is different from '2015/10/28'
                                                                          – PedroC88
                                                                          Jan 5 '16 at 21:14


















                                                                        • Please add some explanation to your answer!
                                                                          – ρss
                                                                          Nov 6 '15 at 14:16










                                                                        • This doesn't work because '2015/10/28 00:00.001' is different from '2015/10/28'
                                                                          – PedroC88
                                                                          Jan 5 '16 at 21:14
















                                                                        Please add some explanation to your answer!
                                                                        – ρss
                                                                        Nov 6 '15 at 14:16




                                                                        Please add some explanation to your answer!
                                                                        – ρss
                                                                        Nov 6 '15 at 14:16












                                                                        This doesn't work because '2015/10/28 00:00.001' is different from '2015/10/28'
                                                                        – PedroC88
                                                                        Jan 5 '16 at 21:14




                                                                        This doesn't work because '2015/10/28 00:00.001' is different from '2015/10/28'
                                                                        – PedroC88
                                                                        Jan 5 '16 at 21:14










                                                                        up vote
                                                                        0
                                                                        down vote













                                                                        Test this query.



                                                                        SELECT *,DATE(chat_reg_date) AS is_date,TIME(chat_reg_time) AS is_time FROM chat WHERE chat_inbox_key='$chat_key' 
                                                                        ORDER BY is_date DESC, is_time DESC





                                                                        share|improve this answer

























                                                                          up vote
                                                                          0
                                                                          down vote













                                                                          Test this query.



                                                                          SELECT *,DATE(chat_reg_date) AS is_date,TIME(chat_reg_time) AS is_time FROM chat WHERE chat_inbox_key='$chat_key' 
                                                                          ORDER BY is_date DESC, is_time DESC





                                                                          share|improve this answer























                                                                            up vote
                                                                            0
                                                                            down vote










                                                                            up vote
                                                                            0
                                                                            down vote









                                                                            Test this query.



                                                                            SELECT *,DATE(chat_reg_date) AS is_date,TIME(chat_reg_time) AS is_time FROM chat WHERE chat_inbox_key='$chat_key' 
                                                                            ORDER BY is_date DESC, is_time DESC





                                                                            share|improve this answer












                                                                            Test this query.



                                                                            SELECT *,DATE(chat_reg_date) AS is_date,TIME(chat_reg_time) AS is_time FROM chat WHERE chat_inbox_key='$chat_key' 
                                                                            ORDER BY is_date DESC, is_time DESC






                                                                            share|improve this answer












                                                                            share|improve this answer



                                                                            share|improve this answer










                                                                            answered Apr 6 '17 at 22:18









                                                                            Programer_saeed

                                                                            11725




                                                                            11725






















                                                                                up vote
                                                                                0
                                                                                down vote













                                                                                Simply use this in your WHERE clause.



                                                                                The "SubmitDate" portion below is the column name, so insert your own.



                                                                                This will return only the "Year" portion of the results, omitting the mins etc.



                                                                                Where datepart(year, SubmitDate) = '2017'





                                                                                share|improve this answer



























                                                                                  up vote
                                                                                  0
                                                                                  down vote













                                                                                  Simply use this in your WHERE clause.



                                                                                  The "SubmitDate" portion below is the column name, so insert your own.



                                                                                  This will return only the "Year" portion of the results, omitting the mins etc.



                                                                                  Where datepart(year, SubmitDate) = '2017'





                                                                                  share|improve this answer

























                                                                                    up vote
                                                                                    0
                                                                                    down vote










                                                                                    up vote
                                                                                    0
                                                                                    down vote









                                                                                    Simply use this in your WHERE clause.



                                                                                    The "SubmitDate" portion below is the column name, so insert your own.



                                                                                    This will return only the "Year" portion of the results, omitting the mins etc.



                                                                                    Where datepart(year, SubmitDate) = '2017'





                                                                                    share|improve this answer














                                                                                    Simply use this in your WHERE clause.



                                                                                    The "SubmitDate" portion below is the column name, so insert your own.



                                                                                    This will return only the "Year" portion of the results, omitting the mins etc.



                                                                                    Where datepart(year, SubmitDate) = '2017'






                                                                                    share|improve this answer














                                                                                    share|improve this answer



                                                                                    share|improve this answer








                                                                                    edited Jun 14 '17 at 19:23









                                                                                    whrrgarbl

                                                                                    2,47032841




                                                                                    2,47032841










                                                                                    answered Jun 14 '17 at 15:44









                                                                                    user8161541

                                                                                    11




                                                                                    11






















                                                                                        up vote
                                                                                        0
                                                                                        down vote













                                                                                        select *, cast ([col1] as date) <name of the column> from test where date = 'mm/dd/yyyy'


                                                                                        "col1" is name of the column with date and time

                                                                                        <name of the column> here you can change name as desired






                                                                                        share|improve this answer



























                                                                                          up vote
                                                                                          0
                                                                                          down vote













                                                                                          select *, cast ([col1] as date) <name of the column> from test where date = 'mm/dd/yyyy'


                                                                                          "col1" is name of the column with date and time

                                                                                          <name of the column> here you can change name as desired






                                                                                          share|improve this answer

























                                                                                            up vote
                                                                                            0
                                                                                            down vote










                                                                                            up vote
                                                                                            0
                                                                                            down vote









                                                                                            select *, cast ([col1] as date) <name of the column> from test where date = 'mm/dd/yyyy'


                                                                                            "col1" is name of the column with date and time

                                                                                            <name of the column> here you can change name as desired






                                                                                            share|improve this answer














                                                                                            select *, cast ([col1] as date) <name of the column> from test where date = 'mm/dd/yyyy'


                                                                                            "col1" is name of the column with date and time

                                                                                            <name of the column> here you can change name as desired







                                                                                            share|improve this answer














                                                                                            share|improve this answer



                                                                                            share|improve this answer








                                                                                            edited Apr 20 at 7:32









                                                                                            Filnor

                                                                                            1,08121524




                                                                                            1,08121524










                                                                                            answered Apr 20 at 6:10









                                                                                            NGoyal

                                                                                            11




                                                                                            11






















                                                                                                up vote
                                                                                                0
                                                                                                down vote













                                                                                                select *
                                                                                                from invoice
                                                                                                where TRUNC(created_date) <=TRUNC(to_date('04-MAR-18 15:00:00','dd-mon-yy hh24:mi:ss'));





                                                                                                share|improve this answer



























                                                                                                  up vote
                                                                                                  0
                                                                                                  down vote













                                                                                                  select *
                                                                                                  from invoice
                                                                                                  where TRUNC(created_date) <=TRUNC(to_date('04-MAR-18 15:00:00','dd-mon-yy hh24:mi:ss'));





                                                                                                  share|improve this answer

























                                                                                                    up vote
                                                                                                    0
                                                                                                    down vote










                                                                                                    up vote
                                                                                                    0
                                                                                                    down vote









                                                                                                    select *
                                                                                                    from invoice
                                                                                                    where TRUNC(created_date) <=TRUNC(to_date('04-MAR-18 15:00:00','dd-mon-yy hh24:mi:ss'));





                                                                                                    share|improve this answer














                                                                                                    select *
                                                                                                    from invoice
                                                                                                    where TRUNC(created_date) <=TRUNC(to_date('04-MAR-18 15:00:00','dd-mon-yy hh24:mi:ss'));






                                                                                                    share|improve this answer














                                                                                                    share|improve this answer



                                                                                                    share|improve this answer








                                                                                                    edited Apr 26 at 3:12









                                                                                                    Pang

                                                                                                    6,8021563101




                                                                                                    6,8021563101










                                                                                                    answered Apr 26 at 1:51









                                                                                                    PanSQL

                                                                                                    1




                                                                                                    1






















                                                                                                        up vote
                                                                                                        0
                                                                                                        down vote













                                                                                                        There is a problem with dates and languages and the way to avoid it is asking for dates with this format YYYYMMDD.



                                                                                                        This way below should be the fastest according to the link below. I checked in SQL Server 2012 and I agree with the link.



                                                                                                        select * from test where date >= '20141903' AND date < DATEADD(DAY, 1, '20141903');



                                                                                                        • Bad habits to kick : mis-handling date / range queries






                                                                                                        share|improve this answer



























                                                                                                          up vote
                                                                                                          0
                                                                                                          down vote













                                                                                                          There is a problem with dates and languages and the way to avoid it is asking for dates with this format YYYYMMDD.



                                                                                                          This way below should be the fastest according to the link below. I checked in SQL Server 2012 and I agree with the link.



                                                                                                          select * from test where date >= '20141903' AND date < DATEADD(DAY, 1, '20141903');



                                                                                                          • Bad habits to kick : mis-handling date / range queries






                                                                                                          share|improve this answer

























                                                                                                            up vote
                                                                                                            0
                                                                                                            down vote










                                                                                                            up vote
                                                                                                            0
                                                                                                            down vote









                                                                                                            There is a problem with dates and languages and the way to avoid it is asking for dates with this format YYYYMMDD.



                                                                                                            This way below should be the fastest according to the link below. I checked in SQL Server 2012 and I agree with the link.



                                                                                                            select * from test where date >= '20141903' AND date < DATEADD(DAY, 1, '20141903');



                                                                                                            • Bad habits to kick : mis-handling date / range queries






                                                                                                            share|improve this answer














                                                                                                            There is a problem with dates and languages and the way to avoid it is asking for dates with this format YYYYMMDD.



                                                                                                            This way below should be the fastest according to the link below. I checked in SQL Server 2012 and I agree with the link.



                                                                                                            select * from test where date >= '20141903' AND date < DATEADD(DAY, 1, '20141903');



                                                                                                            • Bad habits to kick : mis-handling date / range queries







                                                                                                            share|improve this answer














                                                                                                            share|improve this answer



                                                                                                            share|improve this answer








                                                                                                            edited Nov 10 at 21:22









                                                                                                            Aaron Bertrand

                                                                                                            205k27357401




                                                                                                            205k27357401










                                                                                                            answered Dec 1 '16 at 22:18









                                                                                                            mako

                                                                                                            6816




                                                                                                            6816






















                                                                                                                up vote
                                                                                                                -1
                                                                                                                down vote













                                                                                                                select * from invoice where TRANS_DATE_D>= to_date  ('20170831115959','YYYYMMDDHH24MISS')
                                                                                                                and TRANS_DATE_D<= to_date ('20171031115959','YYYYMMDDHH24MISS');





                                                                                                                share|improve this answer























                                                                                                                • I think this is Oracle syntax, do not work at sql server
                                                                                                                  – ceinmart
                                                                                                                  Mar 14 at 13:53















                                                                                                                up vote
                                                                                                                -1
                                                                                                                down vote













                                                                                                                select * from invoice where TRANS_DATE_D>= to_date  ('20170831115959','YYYYMMDDHH24MISS')
                                                                                                                and TRANS_DATE_D<= to_date ('20171031115959','YYYYMMDDHH24MISS');





                                                                                                                share|improve this answer























                                                                                                                • I think this is Oracle syntax, do not work at sql server
                                                                                                                  – ceinmart
                                                                                                                  Mar 14 at 13:53













                                                                                                                up vote
                                                                                                                -1
                                                                                                                down vote










                                                                                                                up vote
                                                                                                                -1
                                                                                                                down vote









                                                                                                                select * from invoice where TRANS_DATE_D>= to_date  ('20170831115959','YYYYMMDDHH24MISS')
                                                                                                                and TRANS_DATE_D<= to_date ('20171031115959','YYYYMMDDHH24MISS');





                                                                                                                share|improve this answer














                                                                                                                select * from invoice where TRANS_DATE_D>= to_date  ('20170831115959','YYYYMMDDHH24MISS')
                                                                                                                and TRANS_DATE_D<= to_date ('20171031115959','YYYYMMDDHH24MISS');






                                                                                                                share|improve this answer














                                                                                                                share|improve this answer



                                                                                                                share|improve this answer








                                                                                                                edited Sep 5 '17 at 7:13









                                                                                                                Jens

                                                                                                                51.8k125174




                                                                                                                51.8k125174










                                                                                                                answered Sep 5 '17 at 6:55









                                                                                                                khairollah royesh

                                                                                                                1




                                                                                                                1












                                                                                                                • I think this is Oracle syntax, do not work at sql server
                                                                                                                  – ceinmart
                                                                                                                  Mar 14 at 13:53


















                                                                                                                • I think this is Oracle syntax, do not work at sql server
                                                                                                                  – ceinmart
                                                                                                                  Mar 14 at 13:53
















                                                                                                                I think this is Oracle syntax, do not work at sql server
                                                                                                                – ceinmart
                                                                                                                Mar 14 at 13:53




                                                                                                                I think this is Oracle syntax, do not work at sql server
                                                                                                                – ceinmart
                                                                                                                Mar 14 at 13:53










                                                                                                                up vote
                                                                                                                -2
                                                                                                                down vote













                                                                                                                SELECT * FROM test where DATEPART(year,[TIMESTAMP]) = '2018'  and  DATEPART(day,[TIMESTAMP]) = '16' and  DATEPART(month,[TIMESTAMP]) = '11'





                                                                                                                share|improve this answer










                                                                                                                New contributor




                                                                                                                Kalidas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                Check out our Code of Conduct.






















                                                                                                                  up vote
                                                                                                                  -2
                                                                                                                  down vote













                                                                                                                  SELECT * FROM test where DATEPART(year,[TIMESTAMP]) = '2018'  and  DATEPART(day,[TIMESTAMP]) = '16' and  DATEPART(month,[TIMESTAMP]) = '11'





                                                                                                                  share|improve this answer










                                                                                                                  New contributor




                                                                                                                  Kalidas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                  Check out our Code of Conduct.




















                                                                                                                    up vote
                                                                                                                    -2
                                                                                                                    down vote










                                                                                                                    up vote
                                                                                                                    -2
                                                                                                                    down vote









                                                                                                                    SELECT * FROM test where DATEPART(year,[TIMESTAMP]) = '2018'  and  DATEPART(day,[TIMESTAMP]) = '16' and  DATEPART(month,[TIMESTAMP]) = '11'





                                                                                                                    share|improve this answer










                                                                                                                    New contributor




                                                                                                                    Kalidas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                    Check out our Code of Conduct.









                                                                                                                    SELECT * FROM test where DATEPART(year,[TIMESTAMP]) = '2018'  and  DATEPART(day,[TIMESTAMP]) = '16' and  DATEPART(month,[TIMESTAMP]) = '11'






                                                                                                                    share|improve this answer










                                                                                                                    New contributor




                                                                                                                    Kalidas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                    Check out our Code of Conduct.









                                                                                                                    share|improve this answer



                                                                                                                    share|improve this answer








                                                                                                                    edited 2 days ago









                                                                                                                    pushkin

                                                                                                                    3,673102450




                                                                                                                    3,673102450






                                                                                                                    New contributor




                                                                                                                    Kalidas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                    Check out our Code of Conduct.









                                                                                                                    answered 2 days ago









                                                                                                                    Kalidas

                                                                                                                    11




                                                                                                                    11




                                                                                                                    New contributor




                                                                                                                    Kalidas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                    Check out our Code of Conduct.





                                                                                                                    New contributor





                                                                                                                    Kalidas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                    Check out our Code of Conduct.






                                                                                                                    Kalidas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                                                    Check out our Code of Conduct.






























                                                                                                                         

                                                                                                                        draft saved


                                                                                                                        draft discarded



















































                                                                                                                         


                                                                                                                        draft saved


                                                                                                                        draft discarded














                                                                                                                        StackExchange.ready(
                                                                                                                        function () {
                                                                                                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22506930%2fhow-to-query-datetime-field-using-only-date-in-sql-server%23new-answer', 'question_page');
                                                                                                                        }
                                                                                                                        );

                                                                                                                        Post as a guest















                                                                                                                        Required, but never shown





















































                                                                                                                        Required, but never shown














                                                                                                                        Required, but never shown












                                                                                                                        Required, but never shown







                                                                                                                        Required, but never shown

































                                                                                                                        Required, but never shown














                                                                                                                        Required, but never shown












                                                                                                                        Required, but never shown







                                                                                                                        Required, but never shown







                                                                                                                        Popular posts from this blog

                                                                                                                        Bressuire

                                                                                                                        Vorschmack

                                                                                                                        Quarantine