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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL script to implement FUNCTIONS

Status
Not open for further replies.

blackbirdMIT

IS-IT--Management
Aug 28, 2003
22
0
0
US
Can you please give me some tips to...
create an SQL script that implements three functions: MonthsUntil, DaysUntil, and HoursUntil.

wherein I can input date value
then the functions will return the number of months until the date, days until the date, or hours until the date as appropriate.

 
The DateDiff function is all you need.

Syntax is DATEDIFF ( datepart , startdate , enddate ).

Example:

select DATEDIFF ( "month" , '09/11/2001' , getdate()) -- 24
select DATEDIFF ( "day" , '09/11/2001' , getdate()) -- 723
select DATEDIFF ( "hour" , '09/11/2001' , getdate()) -- 17366





 
Is that the straight forward of calling the function and assigning the parameters?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top