Convert Manual Date to DateTime

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
3 posts Page 1 of 1
Contributors
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Convert Manual Date to DateTime
Dummy1912
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
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
SumCode
Dedicated Member
Dedicated Member
Posts: 57
Joined: Fri Aug 03, 2012 2:34 am

Re: Convert Manual Date to DateTime
SumCode
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
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

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

+rep for sure
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
3 posts Page 1 of 1
Return to “Coding Help & Support”