Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculated Date Default Values

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0

Hi all,
I need a way to create a default value for a datetime
field which gives me the first day of the next month.
In other words if today is 7/21/02 my default value
would be 8/1/02, or if the current date is 8/1/02 it
would return 9/1/02. Any help is greatly
appreciated.

Thanks,
Dave




 
A quick solution:

Code:
select cast(cast(datepart(month, dateadd(month,1,getdate())) as varchar(2)) + '/1/' + cast(datepart(year, dateadd(month, 1, getdate())) as varchar(4)) as datetime)

Note: It's important that the new date (i.e. dateadd(month, 1, getdate()) is used for the year portion since 12/12/2002 should yield 1/1/2003, not 1/1/2002.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top