By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,387 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,387 IT Pros & Developers. It's quick & easy.

Formatting a datetime value

P: n/a
I'm trying to format a date and time value to a format that is not the same
as in the regional settings.

What I mean is:

Regional setting is set to US "MM/dd/yyyy".

I want to change the format to display as UK "dd/MM/yyyy".

So that I can make some comparisons later on in my program using UK format.

Everytime I try this I get an error.

Can anyone help me out!
Nov 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
* "Simon Osborn" <so*****@microsoft.com> scripsit:
I'm trying to format a date and time value to a format that is not the same
as in the regional settings.

What I mean is:

Regional setting is set to US "MM/dd/yyyy".

I want to change the format to display as UK "dd/MM/yyyy".


'DateTime.ToString(<format>)'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2

P: n/a
Thanks for the speedy reply.

I've have tried that approach but it will only work if I format the datetime
the same as what is set in the regional settings.

Either that or or I'm doing something drastically wrong.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:c6************@ID-208219.news.uni-berlin.de...
* "Simon Osborn" <so*****@microsoft.com> scripsit:
I'm trying to format a date and time value to a format that is not the same as in the regional settings.

What I mean is:

Regional setting is set to US "MM/dd/yyyy".

I want to change the format to display as UK "dd/MM/yyyy".


'DateTime.ToString(<format>)'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #3

P: n/a
Hi Simon,

Take a look at 'date format' inside vs .net. There are several examples and
a full list of options - here's a few:

MyStr = Format(MyDateTime, "h:m:s") ' Returns "5:4:23".
MyStr = Format(MyDateTime, "hh:mm:ss tt") ' Returns "05:04:23 PM".
mdatestring = mdate.ToString("yyyyMMdd")

HTH,

Bernie Yaeger

"Simon Osborn" <so*****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I'm trying to format a date and time value to a format that is not the same as in the regional settings.

What I mean is:

Regional setting is set to US "MM/dd/yyyy".

I want to change the format to display as UK "dd/MM/yyyy".

So that I can make some comparisons later on in my program using UK format.
Everytime I try this I get an error.

Can anyone help me out!

Nov 20 '05 #4

P: n/a
On Wed, 28 Apr 2004 13:56:10 +0100, Simon Osborn wrote:
I want to change the format to display as UK "dd/MM/yyyy".
You can use the DateTime.ToString method:

Dim strDisplayDate As String = dTheDate.ToString("dd/MM/yyy")

So that I can make some comparisons later on in my program using UK format.

To create a DateTime with a different culture, you can do the following:

'Create a CultureInfo for "English - United Kingdom"
Dim culture As New CultureInfo("en-GB", True)
Dim sUKDate As String = "28/04/2004"
Dim dUK As DateTime
dUK = DateTime.Parse(sUKDate,culture,DateTimeStyles.NoCu rrentDateDefault)
Everytime I try this I get an error.


What error do you get?

--
Chris

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 20 '05 #5

P: n/a
* "Simon Osborn" <so*****@microsoft.com> scripsit:
I've have tried that approach but it will only work if I format the datetime
the same as what is set in the regional settings.

Either that or or I'm doing something drastically wrong.


Try to mask all the "/" with "\/".

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #6

P: n/a
Ben
Do a search in your vb help files for datetime customformat
Nov 20 '05 #7

P: n/a
* =?Utf-8?B?QmVu?= <an*******@discussions.microsoft.com> scripsit:
Do a search in your vb help files for datetime customformat


<URL:http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDateTimeClassToStringTopic1.asp>
<URL:http://msdn.microsoft.com/library/en-us/cpguide/html/cpcondatetimeformatstrings.asp>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8

P: n/a
I still get problems when comparing later on... i.e. using datediff.

What I don't want to have to do is worry about what the regional settings
are. I want to be able to format to what ever I want and if need be do a
datediff or anything along those lines.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:c6************@ID-208219.news.uni-berlin.de...
* =?Utf-8?B?QmVu?= <an*******@discussions.microsoft.com> scripsit:
Do a search in your vb help files for datetime customformat

<URL:http://msdn.microsoft.com/library/en...ystemDateTimeC
lassToStringTopic1.asp> <URL:http://msdn.microsoft.com/library/en...ndatetimeforma
tstrings.asp>
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #9

P: n/a
* "Simon Osborn" <so*****@microsoft.com> scripsit:
I still get problems when comparing later on... i.e. using datediff.

What I don't want to have to do is worry about what the regional settings
are. I want to be able to format to what ever I want and if need be do a
datediff or anything along those lines.


Format doesn't have anything to do with 'DateDiff'. The format is only
used to get a "human readable" string representation of the 'DateTime''s
value. Post your code.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.