Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. DateTime from concatenated string

DateTime from concatenated string

Scheduled Pinned Locked Moved Database
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jay Royall
    wrote on last edited by
    #1

    Hi, I am trying to insert into a DateTime field by concatenating a string and a nVarChar field like so:

    CONVERT(datetime, '1/1/' + tblMembershipRecords.[YearJoined], 103)

    But I get a message stating; 'Conversion failed when converting datetime from character string.' Any ideas what is going wrong?

    L 1 Reply Last reply
    0
    • J Jay Royall

      Hi, I am trying to insert into a DateTime field by concatenating a string and a nVarChar field like so:

      CONVERT(datetime, '1/1/' + tblMembershipRecords.[YearJoined], 103)

      But I get a message stating; 'Conversion failed when converting datetime from character string.' Any ideas what is going wrong?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Liqz wrote:

      Any ideas what is going wrong?

      The computer tries to "interpret" your string as a date, and it doesn't understand it. It seems that it expects the date to be in a different format. Try something like this;

      SELECT DATEADD(y, tblMembershipRecords.[YearJoined], getdate())

      That will add a single year to the DateTime, without converting it to a string.

      I are Troll :)

      J 1 Reply Last reply
      0
      • L Lost User

        Liqz wrote:

        Any ideas what is going wrong?

        The computer tries to "interpret" your string as a date, and it doesn't understand it. It seems that it expects the date to be in a different format. Try something like this;

        SELECT DATEADD(y, tblMembershipRecords.[YearJoined], getdate())

        That will add a single year to the DateTime, without converting it to a string.

        I are Troll :)

        J Offline
        J Offline
        Jay Royall
        wrote on last edited by
        #3

        Got it, thanks for the tip, all working now :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups