Total Page Preview:   000000004181

How to convert date function and format in SQL in English and Hindi

 

SQL convert date function and format in English

In SQL, the CONVERT() function is used to convert a value from one data type to another. This function can also be used to convert dates between different formats.

The basic syntax for the CONVERT() function is:
Here, data_type is the data type you want to convert the expression to, expression is the value you want to convert, and style is the style of the output. In the case of date conversion, the style parameter determines the format of the output date.
 
Here's an example of how to use the CONVERT() function to convert a date to a different format:
Suppose you have a table called orders that contains the following data:
Now, let's say you want to convert the order_date values from the default format (yyyy-mm-dd hh:mm:ss) to a different format, such as mm/dd/yyyy hh:mm:ss. You can do this using the following SQL statement:
This statement uses the CONVERT() function to convert the order_date values to the VARCHAR data type with a length of 19 characters, and specifies a style of 101, which corresponds to the mm/dd/yyyy format. The resulting output would look like this:
As you can see, the order_date values have been converted to the specified format.
 
It's important to note that the style parameter used in the CONVERT() function can vary depending on the desired output format. Some common style codes for date conversion are:
  • 101 = mm/dd/yyyy
  • 102 = yyyy.mm.dd
  • 103 = dd/mm/yyyy
  • 104 = dd.mm.yyyy
  • 105 = dd-mm-yyyy
  • 106 = dd mon yyyy
  • 107 = mon dd, yyyy
  • 108 = hh:mm:ss
It's also important to note that the output format of the date can vary depending on the database system being used. So it's always a good idea to check the documentation of your specific database system for the available date conversion styles.
 

 

SQL convert date function and format in Hindi

SQL me date aur time conversion karne ke liye, CAST ya CONVERT functions ka use kiya jata hai. Neeche diye gaye hai kuch examples:
1-Datetime ko date me convert karna:
Output: 2023-04-14
 
2-Date ko datetime me convert karna:
Output: 2023-04-14 00:00:00.000
 
3-Time ko datetime me convert karna:

Output: 15:30:00.0000000
 
4-Date ko string me convert karna:
Output: 04/14/2023
 
In the above example, 101 parameter specifies the format style for conversion. You can use different format codes as per your requirement.
5-Datetime ko string me convert karna:
Output: 2023-04-14 15:30:00
In the above example, 120 parameter specifies the format style for conversion. You can use different format codes as per your requirement.

 

 

 

 

Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com



Comments


                           
                           

                           

                           

Facebook User: