October 3, 2006 at 2:05 pm
Hi everyone,
My date string passed from asp.net to store procedure is format like this mm/dd/yyyy(i.e. 10/3/2006)
while my date format in database is 2006-10-3(yyyy-mm-dd).
What should I do in store procedure to convert the date format from mm/dd/yyyy to yyyy-mm-dd in order to compare the date string and query what I want.
Thank you.
October 3, 2006 at 2:17 pm
Do I have to do something like this:
Declare @sDate Char(10)
select @sDate=Str(Year('9/13/2005'), Len(Year('9/13/2005'))) +'-' + Str(month('9/13/2005'), Len(month('9/13/2005')))+'-'+Str(day('9/13/2005'), Len(day('9/13/2005')))
select @sDate
Is there any easier way?
Thanks.
Betty
October 3, 2006 at 2:30 pm
Are you getting an error? The conversion should be implicit. You could always try REPLACE( CONVERT( varchar, GETDATE(), 102), CHAR(46), CHAR(45))
I wasn't born stupid - I had to study.
October 3, 2006 at 2:31 pm
Thanks everyone. I think I can use:
select convert(char(10),txndate, 101) to let it become mm/dd/yyyy
Betty
October 3, 2006 at 2:37 pm
Farrell,
I didn't get any error.
Betty
October 4, 2006 at 1:00 am
If you use a dateandtime var and a datetime column, use a parameterized query in combination with a datetime parameterobject.
e.g. vbs:
' Handle commandobject
set CmdObj = CreateObject("ADODB.Command")
CmdObj.ActiveConnection = ConnObj
CmdObj.CommandText = "select mycol1 from mytable where mydatetimecol = ? "
CmdObj.CommandType = 1 'adCmdText
'inputparameters
set MyParamObj = CreateObject("ADODB.Parameter")
MyParamObj.Name = "@test"
MyParamObj.Type = 135 'adDBTimeStamp
MyParamObj.Direction = 1 'adParamInput
MyParamObj.Value = yourdateandtimevariable
CmdObj.Parameters.Append MyParamObj
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply