Hi
I have below data in 2 fields. I want to update SessionStartTime Date Part only . Time should remain same
Date Start Time
2023/05/26 2023-05-19 17:00:00.000
Result should be 2023/05/26 17:00:00.000
Thanks
Hi
I have below data in 2 fields. I want to update SessionStartTime Date Part only . Time should remain same
Date Start Time
2023/05/26 2023-05-19 17:00:00.000
Result should be 2023/05/26 17:00:00.000
Thanks
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.
Amit MohantyPosted Apr 24, 2023, 4:02 AM
You can use the
DateTime.ParseExact()method to parse the Start Time field, extract the time portion of it, and then combine it with the SessionStartTime field to create the desired result.Tuhin PaulPosted Apr 24, 2023, 4:00 AM
// Now you can use the newDateTime value to update the SessionStartTime field in the database
In C#, you can use the `DateTime` and `TimeSpan` classes to update the date part of a `DateTime` value while keeping the time part the same. Here we first parse the original `SessionStartTime` value and extract the time part using the `TimeOfDay` property. We then parse the new date value and create a new `DateTime` value by combining the date part from the new date and the time part from the original `SessionStartTime` value. You can use the `newDateTime` value to update the `SessionStartTime` field in the database.
Tuhin PaulPosted Apr 24, 2023, 3:53 AM
You can use the `DATEPART` function to extract the time part from the `Start Time` field and then combine it with the `SessionStartTime` field to create the final result. This query will convert the `SessionStartTime` field to a `datetime` value with the date part only, and then add the hour, minute, and second parts of the `Start Time` field to it. This will result in a `datetime` value with the same time as the `Start Time` field but with the date part of the `SessionStartTime` field.
Ali BenchaabanPosted Apr 23, 2023, 12:23 PM
Hello Ramco,
You can assign an initial value to a new
DateTimevalue in many different ways:Extension method DateTime
BENCHAABAN Ali