codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || 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 Plus Question  LordofRikesh at 14:25 on Friday, March 27, 2009
 

Hi I would like to know how you can find a set of data without today's date.

For example displaying only Building code with number of rooms, with rooms not booked on todays date

The three tables combined here are ROOM, BUILDING & ROOM_BOOKING.

PLEASE EMAIL SOLUTION AT solanki_rikesh@yahoo.co.uk

THANKS.



  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
• C++
• Re: refresh parent after closing pop up window
• Dynamic Insertion
• Date and Time function around the world???
• Significant Factors
• Perl array access
• Re: huffman encoding and decoding in C++...
• Perl One Liner: Replace {(
• Re: html including php, accessing the functions


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-2009