How to write to TO CHAR and TO DATE SQL SERVER
2012-01-31 15:07
274 查看
Select convert(char,EMPJOINDATE,101) as EMPJOINDATE FROM emp;
Additionally, here is how to retrieve the current date and the formats
select convert(char, getdate(), 100) --mon dd yyyy hh:mmAM (or PM)
select convert(char, getdate(), 101) --mm/dd/yyyy
select convert(char, getdate(), 102)
--yyyy.mm.dd
select convert(char, getdate(), 103) --dd/mm/yyyy
select convert(char, getdate(), 104) --dd.mm.yyyy
select convert(char, getdate(), 105) --dd-mm-yyyy
select convert(char, getdate(), 106) --dd mon yyyy
select convert(char, getdate(), 107) --mon dd, yyyy
select convert(char, getdate(), 108) --hh:mm:ss
select convert(char, getdate(), 109) --mon dd yyyy hh:mm:ss:mmmAM (or PM)
select convert(char, getdate(), 110) --mm-dd-yyyy
select convert(char, getdate(), 111) --yyyy/mm/dd
select convert(char, getdate(), 112) --yyyymmdd
select convert(char, getdate(), 113) --dd mon yyyy hh:mm:ss:mmm
select convert(char, getdate(), 114) --hh:mm:ss:mmm(24h)
select convert(char, getdate(), 120) --yyyy-mm-dd hh:mm:ss(24h)
select convert(char, getdate(), 121) --yyyy-mm-dd hh:mm:ss.mmm
Additionally, here is how to retrieve the current date and the formats
select convert(char, getdate(), 100) --mon dd yyyy hh:mmAM (or PM)
select convert(char, getdate(), 101) --mm/dd/yyyy
select convert(char, getdate(), 102)
--yyyy.mm.dd
select convert(char, getdate(), 103) --dd/mm/yyyy
select convert(char, getdate(), 104) --dd.mm.yyyy
select convert(char, getdate(), 105) --dd-mm-yyyy
select convert(char, getdate(), 106) --dd mon yyyy
select convert(char, getdate(), 107) --mon dd, yyyy
select convert(char, getdate(), 108) --hh:mm:ss
select convert(char, getdate(), 109) --mon dd yyyy hh:mm:ss:mmmAM (or PM)
select convert(char, getdate(), 110) --mm-dd-yyyy
select convert(char, getdate(), 111) --yyyy/mm/dd
select convert(char, getdate(), 112) --yyyymmdd
select convert(char, getdate(), 113) --dd mon yyyy hh:mm:ss:mmm
select convert(char, getdate(), 114) --hh:mm:ss:mmm(24h)
select convert(char, getdate(), 120) --yyyy-mm-dd hh:mm:ss(24h)
select convert(char, getdate(), 121) --yyyy-mm-dd hh:mm:ss.mmm
相关文章推荐
- Use the SQL Server CLR to Read and Write Text Files
- How to read and save Images in a Sql Server Database using ADO.NET and C#
- How to setup linked servers for SQL Server and Oracle 64 bit client
- How to setup linked servers for SQL Server and Oracle 64 bit client
- How to backup and restore database in SQL Server
- How to find out the Sql Server version and service pack
- How to use Trusted Connection when SQL server and web Server are on two separate machines.
- How to monitor blocking in SQL Server 2005 and in SQL Server 2000 [ZT-MS]
- How to Get First and Last Day of a Week in SQL Server
- [SQL Server][FILESTREAM] -- How to Detach and Attach a SQL Server FILESTREAM Enabled Database
- How to check if a date is a valid date in Sql Server 2005
- How to format datetime & date in Sql Server 2005
- 转 How to Identify and Delete Duplicate SQL Server Records
- SQL-Server collation, what is it and how to change db/column collation
- CodeSnip: How to Get Id of the Record Using ASP.NET and SQL Server 2000
- How to set up and test a simple OLEDB Linked Server in Microsoft® SQL Server to allow retrieval of d
- [SQL Server][FILESTREAM] -- How to Backup and Restore a SQL Server FILESTREAM Enabled Database
- How to Get First and Last Day of a Month in SQL Server
- How to setup linked servers for SQL Server and Oracle 64 bit client
- How to see all the application errors related to SQL Server and export them to a .csv file.