Date and Time PLEASE.....

  • Hi All,

    I have a column with smalldatetime data type.

    I need to create 2 columns which will have date only and time only values from the existing column.

    I need a SQL query like this.

    Update MyTable Set NewDate = Date(OldDateTime), NewTime = Time(OldDateTime)

  • for date I think you want to use CONVERT(VARCHAR, [date_expression], 101) - this will give you mm/dd/yy;

    for time CONVERT(VARCHAR, [date_expression], 108) - this will give you 00:00:00. Is this want you want?

  • Thanks a lot for your kind help.

    Thats exectly what i was looking for.

  • Also, if you want to make part of the table it is better not to create seperate fields if just for output. You can make expression based columns on the table or better, do a select with those expressions as extra columns in a view.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply