| Author |
Topic |
|
accessdbguru
Starting Member
26 Posts |
Posted - 2012-02-01 : 13:54:15
|
| I need to create a query with current date() - 30. field name is timestamp and it has currentdatetime format. How? |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2012-02-01 : 13:58:14
|
| subtract 30 days or subtract 1 month? (they're not the same)What's the data type? Datetime? --Gail ShawSQL Server MVP |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-02-01 : 13:59:27
|
is there a format named currentdatetime in MS SQL Server? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
accessdbguru
Starting Member
26 Posts |
Posted - 2012-02-01 : 14:08:36
|
| Yes it is DateTime and subtract 30 days. So i guess we need to convert it to DATE format and then subtract DATE()-30. How? |
 |
|
|
accessdbguru
Starting Member
26 Posts |
Posted - 2012-02-01 : 14:11:26
|
| Folks, I have this. Select TimeStamp, Application_Name, PercentValue from dbo.Application_Status where Timestamp = convert (Date() - 30). This doesn't work. Need help? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2012-02-01 : 15:39:01
|
| No, that probably won't work.Does the timestamp column have a time as well as a date (so 2012-01-02 12:43:21.233 for example)?Given today's date (2012-02-01), what is the exact range of dates that you want for the TimeStamp column?--Gail ShawSQL Server MVP |
 |
|
|
namman
Constraint Violating Yak Guru
285 Posts |
Posted - 2012-02-01 : 20:36:07
|
| Select TimeStamp, Application_Name, PercentValue from dbo.Application_Status where Timestamp = convert (Date() - 30).Timestamp datatype is not about date or time, so your query will not work. Look like your database is badly designed. That column should be datetime or date data type. Timestamp is mainly used to compare data of the row between 2 reads, not for datetime purpose. |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2012-02-02 : 04:31:53
|
quote: Originally posted by namman Timestamp datatype is not about date or time, so your query will not work.
The column is named timespan, the OP confirmed earlier that it is of type datetime.--Gail ShawSQL Server MVP |
 |
|
|
|