September 04, 2010, 05:01:19 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  Home Help Media Affiliates Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: [MSSQL] Adding days to date  (Read 871 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2620
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
Javaforums.net :: a community about Java software development.
« on: February 22, 2010, 09:31:41 AM »

 Logged
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
ashish
Member
*

Reputation: 0
Offline Offline
Posts: 27
Referrals: 0

Awards
« Reply #2 on: August 12, 2010, 01:33:45 AM »

yes it good. follow all students that one. dance dance dance


SELECT top 1 getdate() AS currentDate, dateadd(d,7,getDate()) AS newDate FROM tblName.
 regards,
phe9oxis,
« Last Edit: August 12, 2010, 02:20:17 AM by Arkie » Logged
Javaforums.net :: a community about Java software development.
   

 Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Valid XHTML 1.0! Valid CSS!
Page created in 0.313 seconds with 35 queries.

Google visited last this page Yesterday at 08:00:28 AM