codetoad.com
Home||ASP|ASP.Net|C++/C#|DHTML|HTML|Java|Javascript|Perl|VB|XML||CodeToadPlus!||Forums||RAM
Search Site:
Search Forums:
SQL Date catalyst at 11:42 on Wednesday, October 05, 2005

Hi there

I need to run an SQL 2000 query where the data it returns is for todays date - 2 days i.e 2 days ago

Can anyone help?


Re: SQL Date Romel Evans at 06:47 on Sunday, October 09, 2005

I think you can do something like the following:
convert(varchar,substring(convert(varchar, getdate(), 121),1,4) + substring(convert(varchar, getdate(), 121),6,2) +
cast(cast(substring(convert(varchar, getdate(), 121),9,2)) as Integer) - 2) as varchar(2).

It's going to be just a bit more complicated to make sure that you have the right month and year, in case today's date is something like January 1st.

Romel Evans

Re: SQL Date javabits at 18:13 on Monday, October 10, 2005

If memory serves me correctly you can just do a normal addition/subtraction.

SELECT GETDATE ( ) - 2
GO

Alternatively you can use the DATEADD function.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_da-db_3vtw.asp

That would be invoked with something like:
DATEADD( day, -2, GETDATE() )

You can also use decimals instead of whole numbers.

semper fi...

Re: SQL Date catalyst at 08:27 on Tuesday, October 11, 2005

Thanks for yor response guys, I have tried both ways and they both work perfect thanks for your help

Tim

Re: SQL Date Matt John at 09:17 on Wednesday, September 16, 2009

Hi readers,
This is very mysterious query, i also faced that kind of problem when i was doing mcsa certification, then i called my friend for help, he did it correct, i will ask to him for this query;

Thanks









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
matrix addition
Re: Storing data from HTML to Excel or TXT
Re: function within loop problem
Re: Ô‡´ò¥¯¥é¥Ö¤Ï ¥Æ©`¥é©`¥á¥¤¥É£ò£±£±¥¢¥¤¥¢¥ó ¤Î£··¬ ¤Ç¤¹
Re: Replace
Re: タイトリスト AP2アイアン 712�情�
Re: SMS from Perl using HTTP request
Re: Charl Schwartzel
Re: Adhyayan - Annual Student Conference and Online Coding Festival


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


Copyright codetoad.com 2001-2013