Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]   Go Down
  Print  
Author Topic: [MSSQL] Adding days to date  (Read 773 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« on: February 22, 2010, 09:31:41 AM »

Adding days to a date can be done like this:

The following code adds 7days to the current date.

Code
GeSHi (sql):
  1. SELECT top 1 getdate() AS currentDate, dateadd(d,7,getDate()) AS newDate FROM tblName
  2.  
Created by GeSHI 1.0.7.20

Output:
Current date                            New date
2010-02-22 14:27:31.280   2010-03-01 14:27:31.280


Removing days is just a simple:

Code
GeSHi (sql):
  1. SELECT top 1 getdate() AS currentDate, dateadd(d,-7,getDate()) AS newDate FROM tblName
  2.  
Created by GeSHI 1.0.7.20
Output:
Current date                            New date
2010-02-22 14:30:04.137   2010-02-15 14:30:04.137
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
a4722
Junior Member
*

Reputation: 0
Offline Offline
Posts: 3
Referrals: 0

Awards
« Reply #1 on: May 05, 2010, 11:10:02 PM »

spam
« Last Edit: May 06, 2010, 03:20:21 PM by Arkie » Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here