Declare @date_and_time varchar(100)= '04/29/23 01:29:55'
Loading
Declare @date_and_time varchar(100)= '04/29/23 01:29:55'
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Anandu G NathPosted Dec 27, 2023, 8:29 AM
Raj BhattPosted May 7, 2023, 2:53 PM
you can try below code :-
Tuhin PaulPosted May 7, 2023, 3:12 AM
Sachin SinghPosted May 6, 2023, 5:28 PM
also like this
Rajkiran SwainPosted May 6, 2023, 1:56 PM
You can use the `CONVERT` function in SQL Server to convert the string to a datetime data type. Here's an example:
```
DECLARE @date_and_time varchar(100) = '04/29/23 01:29:55'
DECLARE @datetime datetime
SET @datetime = CONVERT(datetime, @date_and_time, 101)
SELECT @datetime
```
In this example, the third parameter of the `CONVERT` function, which is set to 101, specifies the style of the input date string. Style 101 represents the format `mm/dd/yyyy`. The converted datetime value can then be assigned to a datetime variable or used in a query.