Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi dears,

I have this join query:
SQL
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 in format dd-mm-yy. Please guide.
Posted
Updated 18-May-10 23:30pm
v3

You can use CONVERT:
Here you go...
CAST and CONVERT[^]
How to format a Date or DateTime in SQL Server[^]


Thus, you can change format of the date in SQL as below:
SQL
SELECT CONVERT(nvarchar(30),GETDATE(),101) AS MyCustomServerDate

Out here change the 3rd parameter value from 100-114, you can get different formats.
 
Share this answer
 
you can change format like this

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


and you want just dd-mm-yy instead of dd-mm-yyyy then write just 5 instead of 105
 
Share this answer
 
v2
hi friend,

Just try this for date, you will get 100% result

SELECT CONVERT(nvarchar(50),GETDATE(),101) from [Table_name]

insted of 101 you can choose different value upto 100-114.

Biji taklif hoy to amne seva no labh aapjo.

thanks,
mahesh patel(vipsha)
 
Share this answer
 
v2
thanks all you dears for your kind help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900