Nirmal
Nirmal

Reputation: 4829

how to convert time field into string using linq sql?

i am using linq to fetch the data and converting time field into string.

At that time if i have a value 11:00:00 in time field of sql server.

But i am getting "Jan 1 1900 11:00AM" at the time of converting to string.

Please provide me help to fetch only time part.

Thanks in advance..

Upvotes: 0

Views: 576

Answers (2)

Mark Seemann
Mark Seemann

Reputation: 233457

It sounds like the field is of type DateTime. You can use the TimeOfDay property to get only the time part.

timeField.TimeOfDay

Upvotes: 1

Yannick Motton
Yannick Motton

Reputation: 36031

Try this:

yourDateTimeObject.ToString("HH:mm:ss")

Or as Mark Seemann suggested:

yourDateTimeObject.TimeOfDay.ToString()

Upvotes: 1

Related Questions