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

return of datetime? 1

Status
Not open for further replies.

sagn

Programmer
Jun 7, 2001
166
US
Hi,

I would like a stored procedure to return
a datetime variable.

However it complains that it needs an int.

Is there a way to return it without
doing a convert or cast?

The SP looks like

<START>

blah blah

declare @TIME datetime
SET @TIME = GETDATE()

blah blah

return @TIME
<END>

Thanks!

ds
 
Hi there,
in SQL you can use return statement only for returning the status (integer). However you can use output parameter or SQL resultset for returning your desired type.

If more help reuired, you are welcome.
 
Thanks! I should have realized.


ds
 
Say Rajeev,

How do I insert a TIME only in a datetime character minus the date

e.g. 0000-00-0000 21:00:00

thanks.

Randy : )
 
hi randy.
SQL does not store date and time values separately so the short answer to your question is: you can't :-(
what you can do, however, is enter the time data as you wish and let SQL do its own thing with the date (it will automatically store it as 01/01/1900 - or something like that). when you want to display this time field, you can format it in a way so that the date is not seen. try something like this:
convert(varchar,<datetime_field>,108)

to find out more about formatting datetime values, see BOL and search for 'cast' or 'convert'.
 
thanks redham.

however, i would like to store the result in a datetime type field. can i still use the CONVERT(VARCHAR(@DaTE),108)
 
You can also use datepart to pick out
the parts of the date you want to use...


ie datepart(hh,sqldatetime) will return the hour,
mi the minutes and ss the seconds...


ds
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top