Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Problems formating date

Reply
 
Old 06-09-2009   #1 (permalink)
Søren D


 
 

Problems formating date

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.


My System SpecsSystem Spec
Old 06-10-2009   #2 (permalink)
Marcel Overweel


 
 

Re: Problems formating date


"Søren D" <null@xxxxxx> schreef in bericht
news:uyot$5S6JHA.1416@xxxxxx
Quote:

>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


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Date problems in MS-DOS program Vista installation & setup
Date format problems after applying Vista SP1 Vista General
What problems have you had to date with Vista? General Discussion
Date problems in PS PowerShell
Date/Time Reset Problems Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46