I'm trying to convert a date in yyyymmdd format to yyyy-mm-dd with the following code:
tdrDate = DateTime.ParseExact(dateString, "yyyymmdd", null).ToString("yyyy-MM-dd");
This works the only problem is that when I have a date such as this "20070205" I get back "2007-01-05". I don't know why this is happening, any help is appreciated.
Convert Char 'yyyymmdd' back to Date data types in SQL Server. Now, convert the Character format 'yyyymmdd' to a Date and DateTime data type using CAST and CONVERT. --A. Cast and Convert datatype DATE: SELECT [CharDate], CAST([CharDate] AS DATE) as 'Date-CAST', CONVERT(DATE,[CharDate]) as 'Date-CONVERT' FROM [dbo].
To format a date as YYYYMMDD : Use the getFullYear() , getMonth() and getDate() methods to get the year, month and day of the date. Add a leading zero to the day and month digits if the value is less than 10 . Add the results to an array and join them without a separator.
First, pick the cells that contain dates, then right-click and select Format Cells. Select Custom in the Number Tab, then type 'dd-mmm-yyyy' in the Type text box, then click okay. It will format the dates you specify.
tdrDate = DateTime.ParseExact(dateString, "yyyyMMdd", null).ToString("yyyy-MM-dd");
You need MM, not mm. mm is for minutes.
It should be:
DateTime.ParseExact(dateString, "yyyyMMdd", null).ToString("yyyy-MM-dd");
Capital 'MM' in the first date format string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With