• Top Members
    Reps
    Posts
  • 834 Replies
    2585 Replies
  • 716 Replies
    2026 Replies
  • 331 Replies
    1928 Replies

Convert Manual Date to DateTime

Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Locked
User avatar
Dummy1912
VIP - Donator
Posts: 1991

Convert Manual Date to DateTime

Fri May 20, 2016 7:09 pm

Hello,

Can anybody help me please
can't find it on google

i have in my db custom date like

Code: Select all

May22016
May122016
Jan252016
how can i convert this to a datetime?

tried:

Code: Select all

Dim myDateTime As DateTime = DateTime.Parse("May22016")
myDateTime.ToString("MMM d, yyyy ddd") 'want to show it like May 2, 2016 Mon
but got error :(

please anyone...

Thanks

User avatar
SumCode
Dedicated Member
Posts: 57

Re: Convert Manual Date to DateTime

Sat May 21, 2016 5:17 am

You can try using Regex:

Code: Select all

var sDate = "May22016";
var fDate = Regex.Replace(sDate, @"^(\w{3})(\d{1,2})(\d{4})$", "$1/$2/$3", RegexOptions.Multiline); //Formats date
var dt = DateTime.ParseExact(fDate, "MMM/d/yyyy", new CultureInfo("en-US"));
Console.WriteLine(dt.ToString("MMM d, yyyy ddd"));

User avatar
Dummy1912
VIP - Donator
Posts: 1991

Re: Convert Manual Date to DateTime

Sat May 21, 2016 5:37 am

Thank you so much dear friend
it worked like a charm :)

+rep for sure

Locked

Return to “Coding Help & Support”