Date Conversion!

Discussion in 'ASP .Net' started by Adam Knight, Oct 6, 2005.

  1. Adam Knight

    Adam Knight Guest

    Hi all,

    I am trying to pass a date parameter into an sql (SQL SERVER) stored
    procedure.

    Initially i was trying to pass the parameter like so:

    cmdReportQuestions.Parameters.Add(New
    SqlParameter("@sdt",Request.Form("txtStartDt")))

    This is obviously incorrect as it is being recieved by my stored procedure
    as nvarchar.
    Thus in my stored procedure i recieve a can not convert data type error.

    How do convert this value to an acceptable data type? (VB.NET)
    The SQL SERVER parameter data type is SMALLDATETIME ?

    Also, the date is in dd/mm/yyyy format.
    Does VB.NET have any formatting functions to convert it to mm/dd/yyyy?

    Cheers,
    Adam
     
    Adam Knight, Oct 6, 2005
    #1
    1. Advertising

  2. Adam Knight

    David Browne Guest

    "Adam Knight" <> wrote in message
    news:...
    > Hi all,
    >
    > I am trying to pass a date parameter into an sql (SQL SERVER) stored
    > procedure.
    >
    > Initially i was trying to pass the parameter like so:
    >
    > cmdReportQuestions.Parameters.Add(New
    > SqlParameter("@sdt",Request.Form("txtStartDt")))
    >


    Check the other constructors for SqlParameter, and inform it of the
    parameter type, or convert the parameter value to a date before you pass it
    in (and it will figure the type out).

    David
     
    David Browne, Oct 6, 2005
    #2
    1. Advertising

  3. try to convert the date to double is easier for u.

    "Adam Knight" wrote:

    > Hi all,
    >
    > I am trying to pass a date parameter into an sql (SQL SERVER) stored
    > procedure.
    >
    > Initially i was trying to pass the parameter like so:
    >
    > cmdReportQuestions.Parameters.Add(New
    > SqlParameter("@sdt",Request.Form("txtStartDt")))
    >
    > This is obviously incorrect as it is being recieved by my stored procedure
    > as nvarchar.
    > Thus in my stored procedure i recieve a can not convert data type error.
    >
    > How do convert this value to an acceptable data type? (VB.NET)
    > The SQL SERVER parameter data type is SMALLDATETIME ?
    >
    > Also, the date is in dd/mm/yyyy format.
    > Does VB.NET have any formatting functions to convert it to mm/dd/yyyy?
    >
    > Cheers,
    > Adam
    >
    >
    >
     
    =?Utf-8?B?RGFuaWVs?=, Oct 7, 2005
    #3
  4. Adam Knight

    Patirck Ige Guest

    Thats it as David adviced
    so what is telling you to do is something like this:-
    Dim parameterDOB As SqlParameter = New SqlParameter("@DOB",
    SqlDbType.SmallDateTime, 4)
    parameterDOB.Value = DOB
    myCommand.Parameters.Add(parameterDOB)

    Or since you are saying its in datatype nvarchar then trying converting it
    to datetime before using the above

    You can also convert to date time using the below sample snippet
    Dim DOB As String = Request.QueryString("DOB")
    If Not DOB Is Nothing Then
    Dim format As New System.Globalization.CultureInfo("en-gb",
    True)
    Dim DateOfBirth As DateTime = DateTime.Parse(DOB, format)
    End If

    And of course you can convert using the FORMAT fucntion like so(lets say you
    have a label control):-
    lblDOB.Text = Format(myOrderDetails.OrderDate, ("dd/MM/yyyy"))

    Hope that helps
    Patrick
    ** How is the weather in QLD?


    "Adam Knight" <> wrote in message
    news:...
    > Hi all,
    >
    > I am trying to pass a date parameter into an sql (SQL SERVER) stored
    > procedure.
    >
    > Initially i was trying to pass the parameter like so:
    >
    > cmdReportQuestions.Parameters.Add(New
    > SqlParameter("@sdt",Request.Form("txtStartDt")))
    >
    > This is obviously incorrect as it is being recieved by my stored procedure
    > as nvarchar.
    > Thus in my stored procedure i recieve a can not convert data type error.
    >
    > How do convert this value to an acceptable data type? (VB.NET)
    > The SQL SERVER parameter data type is SMALLDATETIME ?
    >
    > Also, the date is in dd/mm/yyyy format.
    > Does VB.NET have any formatting functions to convert it to mm/dd/yyyy?
    >
    > Cheers,
    > Adam
    >
    >
     
    Patirck Ige, Oct 7, 2005
    #4
  5. Adam Knight

    Adam Knight Guest

    Hi Patrick,

    I like the look of the format function, but can't seem to find any info on
    the parameters it recieves.
    Can you direct me to some info..?

    Weather:
    Getting a little to hot for my liking, expecting 37 C tommorrow apparently..

    Adam
    "Patirck Ige" <> wrote in message
    news:%...
    > Thats it as David adviced
    > so what is telling you to do is something like this:-
    > Dim parameterDOB As SqlParameter = New SqlParameter("@DOB",
    > SqlDbType.SmallDateTime, 4)
    > parameterDOB.Value = DOB
    > myCommand.Parameters.Add(parameterDOB)
    >
    > Or since you are saying its in datatype nvarchar then trying converting
    > it
    > to datetime before using the above
    >
    > You can also convert to date time using the below sample snippet
    > Dim DOB As String = Request.QueryString("DOB")
    > If Not DOB Is Nothing Then
    > Dim format As New System.Globalization.CultureInfo("en-gb",
    > True)
    > Dim DateOfBirth As DateTime = DateTime.Parse(DOB, format)
    > End If
    >
    > And of course you can convert using the FORMAT fucntion like so(lets say
    > you
    > have a label control):-
    > lblDOB.Text = Format(myOrderDetails.OrderDate, ("dd/MM/yyyy"))
    >
    > Hope that helps
    > Patrick
    > ** How is the weather in QLD?
    >
    >
    > "Adam Knight" <> wrote in message
    > news:...
    >> Hi all,
    >>
    >> I am trying to pass a date parameter into an sql (SQL SERVER) stored
    >> procedure.
    >>
    >> Initially i was trying to pass the parameter like so:
    >>
    >> cmdReportQuestions.Parameters.Add(New
    >> SqlParameter("@sdt",Request.Form("txtStartDt")))
    >>
    >> This is obviously incorrect as it is being recieved by my stored
    >> procedure
    >> as nvarchar.
    >> Thus in my stored procedure i recieve a can not convert data type error.
    >>
    >> How do convert this value to an acceptable data type? (VB.NET)
    >> The SQL SERVER parameter data type is SMALLDATETIME ?
    >>
    >> Also, the date is in dd/mm/yyyy format.
    >> Does VB.NET have any formatting functions to convert it to mm/dd/yyyy?
    >>
    >> Cheers,
    >> Adam
    >>
    >>

    >
    >
     
    Adam Knight, Oct 7, 2005
    #5
  6. Adam Knight

    Patirck Ige Guest

    Are you talking about this format:-
    Dim DateOfBirth As DateTime = DateTime.Parse(DOB, format)
    The DOB is the querystring params and you are parsing it as a DATETIME
    The format is just setting it as a en-gb culture
    OR do you mean this one lblDOB.Text = Format(myOrderDetails.OrderDate,
    ("dd/MM/yyyy"))
    For instance if you param is :- Request.Form("txtStartDt")
    the you can do:-
    StartDt = Format(Request.Form("txtStartDt"),("dd/MM/yyyy"))
    Hope that helps
    Patrick



    "Adam Knight" <> wrote in message
    news:...
    > Hi Patrick,
    >
    > I like the look of the format function, but can't seem to find any info

    on
    > the parameters it recieves.
    > Can you direct me to some info..?
    >
    > Weather:
    > Getting a little to hot for my liking, expecting 37 C tommorrow

    apparently..
    >
    > Adam
    > "Patirck Ige" <> wrote in message
    > news:%...
    > > Thats it as David adviced
    > > so what is telling you to do is something like this:-
    > > Dim parameterDOB As SqlParameter = New SqlParameter("@DOB",
    > > SqlDbType.SmallDateTime, 4)
    > > parameterDOB.Value = DOB
    > > myCommand.Parameters.Add(parameterDOB)
    > >
    > > Or since you are saying its in datatype nvarchar then trying converting
    > > it
    > > to datetime before using the above
    > >
    > > You can also convert to date time using the below sample snippet
    > > Dim DOB As String = Request.QueryString("DOB")
    > > If Not DOB Is Nothing Then
    > > Dim format As New

    System.Globalization.CultureInfo("en-gb",
    > > True)
    > > Dim DateOfBirth As DateTime = DateTime.Parse(DOB, format)
    > > End If
    > >
    > > And of course you can convert using the FORMAT fucntion like so(lets say
    > > you
    > > have a label control):-
    > > lblDOB.Text = Format(myOrderDetails.OrderDate, ("dd/MM/yyyy"))
    > >
    > > Hope that helps
    > > Patrick
    > > ** How is the weather in QLD?
    > >
    > >
    > > "Adam Knight" <> wrote in message
    > > news:...
    > >> Hi all,
    > >>
    > >> I am trying to pass a date parameter into an sql (SQL SERVER) stored
    > >> procedure.
    > >>
    > >> Initially i was trying to pass the parameter like so:
    > >>
    > >> cmdReportQuestions.Parameters.Add(New
    > >> SqlParameter("@sdt",Request.Form("txtStartDt")))
    > >>
    > >> This is obviously incorrect as it is being recieved by my stored
    > >> procedure
    > >> as nvarchar.
    > >> Thus in my stored procedure i recieve a can not convert data type

    error.
    > >>
    > >> How do convert this value to an acceptable data type? (VB.NET)
    > >> The SQL SERVER parameter data type is SMALLDATETIME ?
    > >>
    > >> Also, the date is in dd/mm/yyyy format.
    > >> Does VB.NET have any formatting functions to convert it to mm/dd/yyyy?
    > >>
    > >> Cheers,
    > >> Adam
    > >>
    > >>

    > >
    > >

    >
    >
     
    Patirck Ige, Oct 7, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    619
    Matthew Speed
    Nov 8, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,300
    Michael Borgwardt
    May 30, 2004
  3. Matt
    Replies:
    2
    Views:
    532
    Pete Becker
    Nov 8, 2003
  4. Matt
    Replies:
    3
    Views:
    734
    Richard Heathfield
    Nov 8, 2003
  5. Sanjeeb
    Replies:
    2
    Views:
    186
Loading...

Share This Page