How can i convert a datetime of type dd-mm-yyyy to dd/mm/yyyy in sql?
I dont want to convert to varchar but to datetime.
Can anyone give me an idea please?
How can i convert a datetime of type dd-mm-yyyy to dd/mm/yyyy in sql? I
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A
DateTimeis aDateTimeis aDateTime– it doesn’t have ” a format” – it’s just aDateTime.The format or display options only come into play when you want to display the
DateTimeas a string.To me, this sounds as if:
dd-mm-yyyyDateTimeand then again display a string representing thatDateTimein thedd/mm/yyyyformatRight??
Check out the MSDN SQL Server Books Online for CAST and CONVERT – it lists all possible, valid, supported string formats representing a date and time.
Format
dd-mm-yyyyis style no. 105, so this will convert your first string:Now you have your
DATETIMEvalue (Nov 23, 2010) in@YourDateTime– just aDateTime, no formatting applied.If you want to display that date value in format
dd/mm/yyyy, which is style no. 103, use this snippet of T-SQL to achieve this:This will display
23/11/2010.