I have a string column which contains the data in the format
25/11/2017 00:00:00
I want to convert it in the format of
25Nov2017
and then reduce 2 days in it , so that the text becomes
23Nov2017
How to achieve this in C#?
Thanks
The best approach is fixing the design bug by assigning the column to a DateTime type rather than a string.
The alternative is converting the date string into a DateTime type either in TSQL or C#. Once the string is converted to a DateTime type it is very easy to add/subtracts days and convert to another string format using standard .NET string formatters.
According to your description, I have made a sample here.You could use c# split() method get the part of 25/11/2017, then again use split get the month value ,lastly you could use switch method to change the value of moth to the Jan or Feb etc.Here is
the demo , I hope it could help you.
You could just the put the method in the pageload event if you want the value of date firstly show just as you want .
Participant
1426 Points
1962 Posts
Change string to date format -ddMMMYYYY
Feb 19, 2019 03:36 PM|venkatzeus|LINK
Hi,
I have a string column which contains the data in the format
I want to convert it in the format of
and then reduce 2 days in it , so that the text becomes
How to achieve this in C#?
Thanks
All-Star
43721 Points
18706 Posts
Re: Change string to date format -ddMMMYYYY
Feb 19, 2019 04:06 PM|mgebhard|LINK
The best approach is fixing the design bug by assigning the column to a DateTime type rather than a string.
The alternative is converting the date string into a DateTime type either in TSQL or C#. Once the string is converted to a DateTime type it is very easy to add/subtracts days and convert to another string format using standard .NET string formatters.
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
Participant
1300 Points
522 Posts
Re: Change string to date format -ddMMMYYYY
Feb 20, 2019 02:26 AM|Wei Zhang|LINK
Hi venkatzeus,
According to your description, I have made a sample here.You could use c# split() method get the part of 25/11/2017, then again use split get the month value ,lastly you could use switch method to change the value of moth to the Jan or Feb etc.Here is the demo , I hope it could help you.
You could just the put the method in the pageload event if you want the value of date firstly show just as you want .
Aspx:
Aspx.cs:
It shows as below:

Best Regards
Wei Zhang
Participant
1426 Points
1962 Posts
Re: Change string to date format -ddMMMYYYY
Feb 21, 2019 02:40 PM|venkatzeus|LINK
Hi,
Thanks. It worked