Author |
Topic |
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2013-10-23 : 13:23:45
|
I want to get the data based on passing dates excluding hrs/mins/secs using >= and <= clausecreateddatetime is a datetime column and want to get last two days (sysdate-2) based rows.select * from T_Prog_ACCTs where createddatetime Thank you very much for the helpful info. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-23 : 13:47:44
|
[code]select * from T_Prog_ACCTs where createddatetime>=DATEADD(dd,DATEDIFF(dd,0,GETDATE()),-2)AND createddatetime < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2013-10-23 : 14:39:08
|
As always , Thank you very much Visakh Sir for all the help. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-24 : 01:31:49
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
djj55
Constraint Violating Yak Guru
352 Posts |
Posted - 2013-10-24 : 07:18:14
|
visakh16, what is the difference between DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0) and CAST(GETDATE() AS DATE)?djj |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-24 : 08:53:31
|
quote: Originally posted by djj55 visakh16, what is the difference between DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0) and CAST(GETDATE() AS DATE)?djj
Both are equivalentone does a type conversion to date datatype whilst other does time part stripping using date functions. date datatype is available only from SQL 2008 onwards so CAST method works only in those versions. Other method works in all versions. I prefer date function method.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
djj55
Constraint Violating Yak Guru
352 Posts |
Posted - 2013-10-24 : 09:02:30
|
visakh16, Thanks for the information.djj |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-24 : 12:10:07
|
you're welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|