Reputation: 165
I have to create a table with the following columns Emp_no [PK], Basic_pay_fixed_at, Date_of_birth
The date format for the Date_of_birth column is dd-mm-yyyy
As far as I know the default format for the date datatype in SQL is yyyy-mm-dd
How do I specify this alternate date format inside the create table command ? So, that when I insert value into the table I can insert in the dd-mm-yyyy format.
Thanks in advance!
Upvotes: 1
Views: 5482
Reputation: 15941
MySQL (and most other RDBMS as far as I know) use YYYY-MM-DD
as the standard string representation and cannot be changed. Any data inserted into such a field must be formatted in this manner, or converted to a true date value using functions such as STR_TO_DATE.
Similarly, selecting a values from a field actually returns datetime types in most client languages, which can then be formatted as needed; or other date functions can be used in the select expressions to yield the desired string.
Upvotes: 1
Reputation: 1101
Dates are stored internal so formatting is for input and output.
This will convert to the style you want for output:
select convert(varchar(10), Date_of_birth, 105) from Table
Upvotes: 0