CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2008
    Posts
    23

    How can i change date format

    hi dears,

    I have this join query

    string qry = "Select Users.UserName, Attendence.TimeIn, Attendence.TimeOut from Users Inner Join Attendence on Users.UserID = Attendence.UserID";

    where TimeIn and TimeOut are date columns and their date format is dd/mm/yy.
    Please tell me how can i change my date format in this join query when retrieving these records from database. I want to show this format like that dd-mm-yy. Pleae guide

  2. #2
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: How can i change date format

    here is a good list for you...

    http://anubhavg.wordpress.com/2009/0...l-server-2005/

    the closest one for you is..

    SELECT convert(varchar, getdate(), 105)

    so your query would now be...

    Code:
    SELECT 
          Users.UserName
          , CONVERT(varchar, Attendence.TimeIn, 105) As 'TimeIn'
          , CONVERT(varchar, Attendence.TimeOut, 105) As 'TimeOut'
    FROM 
          Users
              INNER JOIN Attendence
                   ON Users.UserID = Attendence.UserID
    This is assuming the fields are DateTime fields in the database. If not, you will need to convert them to DateTime, then convert them back to varchar.
    ===============================
    My Blog

Tags for this Thread

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

Featured