Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am fairly new into programming. I have a column in a table that has the birth-date in the following format --"MM/DD/YY". I ran the following select statement on that table

select * from TABLE.NAME where ID = '999999999' and birthdate = '13-JAN-46';


Because of the year being 2 digit it would be hard to tell if the '46' is 1946 or 2046


I am trying to figure out if there is a way I could select from that table and have the birthdate in the following format: "MM/DD/YYYY"


Any help will be appreciated.

Thanks,
Mayo
Posted
Comments
Kornfeld Eliyahu Peter 22-Sep-14 17:13pm    
You missed something! SQL stores date/time in binary format! Unless you made a huge mistake and store date/time as string!!!
RedDk 22-Sep-14 17:30pm    
Look up all your questions with TSQL in BOL for whatever SQL Server you've got installed. BOL: "Books On Line". Not only is this volume riddled with example code, like a jar of olives, pimentoes, but using it from the ssmse interface can be accomplished by highlighting statements and hitting F1. DATEPART, DATETIME, DATEDIFF, are all good starting points ...
Sergey Alexandrovich Kryukov 22-Sep-14 18:49pm    
If you store time, use not string, but time data types, such as DATE.
—SA

1 solution

Assuming the date is stored as a date field then you can display it in the format you want by using

select Convert(varchar(10),[BirthDate],101 ) as BirthDate FROM ....

101 is the Date Codes for MM/DD/YYYY

Refer to http://msdn.microsoft.com/en-nz/library/ms187928.aspx[^] for all date codes.
 
Share this answer
 
Comments
MayFad 23-Sep-14 8:45am    
Thanks so much for your help. That worked.

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