如何更改联接查询中的日期格式? [英] How can I change date format in join query?
本文介绍了如何更改联接查询中的日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的,
我有此联接查询:
Hi dears,
I have this join query:
Select Users.UserName, Attendence.TimeIn, Attendence.TimeOut from Users Inner Join Attendence on Users.UserID = Attendence.UserID
其中TimeIn和TimeOut是日期列,其日期格式为dd/mm/yy.请告诉我从数据库中检索这些记录时如何更改此联接查询中的日期格式.我想以dd-mm-yy格式显示.请指导.
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.
推荐答案
您可以使用转换:
你去...
CAST和CONVERT [如何在SQL Server中格式化日期或日期时间 [^ ]
因此,您可以按以下方式在SQL中更改日期的格式:
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:
SELECT CONVERT(nvarchar(30),GETDATE(),101) AS MyCustomServerDate
在这里,将第3个参数的值从100-114更改,您可以得到不同的格式.
Out here change the 3rd parameter value from 100-114, you can get different formats.
您可以更改这样的格式
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
而您只想dd-mm-yy而不是dd-mm-yyyy,然后只写5而不是105
and you want just dd-mm-yy instead of dd-mm-yyyy then write just 5 instead of 105
朋友,
只需尝试一下此日期,您将获得100%的结果
从[表名称] SELECT CONVERT(nvarchar(50),GETDATE(),101)
可以选择101,最多可以选择100-114的其他值.
Biji taklif hoy to amne seva no labh aapjo.
谢谢,
mahesh patel(vipsha)
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)
这篇关于如何更改联接查询中的日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文