开发者

How to apply a particular format of date of birth in a SQL query?

开发者 https://www.devze.com 2023-01-14 22:23 出处:网络
Suppose I want a particular format of date of birth, lik开发者_如何学运维e (mm-dd-yyyy). How can I do that in SQL?Although some people have listed the proper syntax for this in multiple RDBMSs (you r

Suppose I want a particular format of date of birth, lik开发者_如何学运维e (mm-dd-yyyy).

How can I do that in SQL?


Although some people have listed the proper syntax for this in multiple RDBMSs (you really need to indicate which one you're using), I'd like to point out that formatting your data is typically something that should be done by the front end of your application. That's not to say that there's never a reason to do formatting in SQL, but usually it's best to just pass it as a date/time to the front end and let the front end handle how it will represent it to the user. Hopefully, you understand the difference between a date/time and a string.


Use CONVERT function if it is SQL SERVER

Select CONVERT(VARCHAR(10),Birthdate,110) from YourTable


Assuming your RDBMS is SQL Server, you can do the following:

SELECT CONVERT(VARCHAR(10), [DateOfBirth], 110) 

There's more information about date formatting here.


SQL Server

SELECT convert(varchar, getdate(), 110)

SELECT convert(varchar, DateOfBirth, 110) FROM YourTable

How to format datetime & date in Sql Server 2005


If you're using Oracle:

select to_char(your_date_column,'MM-DD-YYYY') from your_date_table;
0

精彩评论

暂无评论...
验证码 换一张
取 消