Home > Database > Mysql Tutorial > How to Convert a VARCHAR Date String to Italian DATETIME Format in SQL Server?

How to Convert a VARCHAR Date String to Italian DATETIME Format in SQL Server?

Barbara Streisand
Release: 2025-01-05 13:48:40
Original
904 people have browsed it

How to Convert a VARCHAR Date String to Italian DATETIME Format in SQL Server?

Converting VARCHAR to DATETIME in SQL Server

Suppose you have a VARCHAR string representing a date in the format '2011-09-28 18:01:00' and you need to convert it to a DATETIME value formatted as '28-09-2011 18:01:00'. Here's how you can achieve this:

Conversion to DATETIME:

To convert the VARCHAR string to a DATETIME value, use the CONVERT function with the appropriate style parameter:

SELECT CONVERT(Datetime, '2011-09-28 18:01:00', 120);
Copy after login

Conversion to Italian Date Format:

To convert the DATETIME value to the Italian date format '28-09-2011 18:01:00', again use the CONVERT function with the style parameter set to 105 for the date portion:

SELECT CONVERT( VARCHAR(30), @date ,105) -- italian format [28-09-2011 18:01:00]
Copy after login

Concatenating Date and Time:

To obtain the complete date and time in the Italian format, you can concatenate the date and time components:

+ ' ' + SELECT CONVERT( VARCHAR(30), @date ,108 ) -- full date [with time/minutes/sec]
Copy after login

The above is the detailed content of How to Convert a VARCHAR Date String to Italian DATETIME Format in SQL Server?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template