Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2002
    Posts
    4

    Unanswered: Issue with cast function

    Hi

    Can someone help me in the following:
    An example is shown below, I had assign a date (format: dd/mm/yyyy) to @vdate. Follow by a cast to vchar. The issue is that the date format is changed after the cast. I would like the date format to remain as dd/mm/yyyy after doing the cast. Hope someone can give some advices. Thanks alot.

    Example:

    declare @vdate as datetime
    set @vdate = convert(datetime,'01/10/2005',103)

    select @vdate --> '10/01/2005' (date format required)

    cast(varchar(20),@vdate) --> 'Oct 1, 2005' (date format changed)

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Dates are not stored in any format. They are actually stored as numeric values, which then are displayed in a requested format.
    Read up in Books Online on the topics of datetime datatypes and the CAST and CONVERT functions.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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