Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Current Date - 30

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 Shaw
SQL Server MVP
Go to Top of Page

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.
Go to Top of Page

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?
Go to Top of Page

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?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-01 : 15:04:42
why are you posting duplicate threads for same issue?

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=170900

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

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 Shaw
SQL Server MVP
Go to Top of Page

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.
Go to Top of Page

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 Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -