Convert Char To Datetime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flickimp
    New Member
    • Dec 2006
    • 37

    Convert Char To Datetime

    I have columns with the following char format:

    06/01/2007 12:00


    I want to convert this to 06/01/2007 so it can be used in a calculation.

    How do I do this?
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    To convert character data to desired style you should convert character data to date first

    convert(datetim e, '06/01/2007 12:00')

    Then this date could be converted to a different style

    convert(varchar (20), convert(datetim e, '06/01/2007 12:00'), 101)

    Comment

    • hariharanmca
      Top Contributor
      • Dec 2006
      • 1977

      #3
      Originally posted by flickimp
      I have columns with the following char format:

      06/01/2007 12:00


      I want to convert this to 06/01/2007 so it can be used in a calculation.

      How do I do this?

      just give search you can get Sol

      Comment

      • nishantgulati
        New Member
        • Mar 2007
        • 1

        #4
        I have columns with the following date format:

        06/01/2007


        I want to convert this to 06/01/2007 00:00:00 AM/PM so it can be used in a calculation.

        how do i do this

        Comment

        • iburyak
          Recognized Expert Top Contributor
          • Nov 2006
          • 1016

          #5
          To convert to datetime for calculations do following
          [PHP]select convert(datetim e, '06/01/2007')[/PHP]

          If you want specific date style for reports use different date styles like this:
          [PHP]select convert(varchar (20), convert(datetim e, '06/01/2007'), 100)[/PHP]


          Good Luck

          Comment

          Working...