Results 1 to 4 of 4

Thread: DatePart error

  1. #1

    Thread Starter
    Lively Member Geemark's Avatar
    Join Date
    Aug 2002
    Location
    At the pc wasting my worthless time
    Posts
    89

    DatePart error

    I hav this field 'Time' in my database (of the type date/time), and I use an System.data.oledb.OLEDBDataReader to read this field.

    When simply response.write(DR.Item('Time')) to the browser i get this:
    12-05-2002 20:05:00

    However, if I use DatePart(DR.Item("Time"),"d") i get this error:
    System.InvalidCastException: Argument 'DateValue' cannot be converted to type 'Date'.

    Any suggestions?
    Machine Language: You try to shoot yourself in
    the foot only to discover you must first reinvent the
    gun, gunpowder, the bullet, and your foot.

  2. #2
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    you're probably better off returning a date from a sql server stored procedure that excludes the time:-

    select convert(datetime, datepart(mm, datefield) + '/' + datepart(dd, datefield) + '/' + datepart(yy, datefield)) as date

    Think that will work.

  3. #3

    Thread Starter
    Lively Member Geemark's Avatar
    Join Date
    Aug 2002
    Location
    At the pc wasting my worthless time
    Posts
    89
    Does that work in OLEDB also? I'm not using MS SQL server...
    Machine Language: You try to shoot yourself in
    the foot only to discover you must first reinvent the
    gun, gunpowder, the bullet, and your foot.

  4. #4
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    It's probably a different function in access. If you search under date functions you should find it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width