I have a Data Table that has a column ‘subscribeDate’ that has dates in MM/dd/yyyy hh:mm:ss format. I would like to change all the dates in this column to MM-dd-yyyy hh:mm:ss format. Is there a way that I can do it without running a loop?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would hope that the values in the
DataTableare of typeDateTimeorDateTimeOffset.Assuming that’s the case, they don’t have a format. They’re just dates and times. How you convert them to a string is up to you.
If they’re not already in an appropriate data type, you should try to change how you obtain the data to start with. Convert it from a string format to a more appropriate data type as early as you possibly can, and only convert it back to a string when you really need to.
You haven’t explained how you’re displaying the
DataTable, but most ways that I’m aware of allow you to specify a format string – that’s where you would specify yourMM-dd-yyyy HH:mm:ssformat. (NoteHHrather thanhh, to get 24 hours.)