Problems formating date

  • Thread starter Thread starter Søren D
  • Start date Start date
S

Søren D

I try to format a date using following

myDateTime.ToString("dd/MM/yyyy")

Which I assumed would give me a date seperated by slashed, but it gives me
the date using '-'.

Can anyone tell me what I am doing wrong? I export to csv and the goal is to
let the user be able specify the date formating.

TIA

Soeren D.
 
Søren D said:
I try to format a date using following

myDateTime.ToString("dd/MM/yyyy")

Which I assumed would give me a date seperated by slashed, but it gives me
the date using '-'.

Can anyone tell me what I am doing wrong? I export to csv and the goal is
to let the user be able specify the date formating.

TIA

Soeren D.

Hi Soeren,

From the .net framework help file:
/ Represents the date separator defined in the current
DateTimeFormatInfo.DateSeparator property.
' Represents a quoted string (apostrophe). Displays the literal value of any
string between two apostrophe (') characters.

In your case, the '/' is translated to a '-' because in your system, the
current date seperator is a '-'.

So you need to use a literal value:

myDateTime.ToString("dd'/'MM'/'yyyy");

or:

mySeperator = "/";
myDateTime.ToString("dd'"+mySeperator+"'MM'"+mySeperator+"'yyyy");

regards,
Marcel
 
Back
Top