Click here to Skip to main content
15,921,226 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello!!!

I am trying to convert datetime to a suitable format but it's not working. It's showing me same date after formatting. I am trying using this

VB
Dim retirement As String = day.ToString() + " - " + month.ToString() + " - " + DateOfRetirement.Year.ToString()
           Dim DOR As DateTime = Date.Parse(retirement)
           DOR = DOR.ToString("D")
           table.Rows(count)("DateOfRetirement") = DOR



But it shows me this as result

10/31/2037 12:00:00 AM

i also tried using

DOR.ToString("dddd, dd MMMM yyyy")

but it shows the same result
Posted

Your coding:
VB
Dim DOR As DateTime = Date.Parse(retirement)

It's natural that after parsing the date-time will be converted in Slandered UTC format. And it'll store like that only. You can change the data-type of your column as string and then you can customize the format easily.
Try this:
VB
'After changing the data type of the column
table.Rows(count)("DateOfRetirement") = DOR.ToString("dd-MMM-yyyy");



--Amit
 
Share this answer
 
use
DOR.ToShortString("dd/MM/yyyy")
 
Share this answer
 
v2
 
Share this answer
 
try to concatenate your DateTimeString using "//" or Better:
C#
DateTime DOR = new DateTime(day, month, DateOfRetirement.Year);

(Dim DOR as DateTime = new ... or something like this in vb.net)

And Afterwards save the ToString() value in a String, not a DateTime!
C#
String s = DOR.ToString();

(Dim s as String = DOR.ToString or something like this in vb.net)

at the end assign the string to the table cell.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900