473,471 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Formatting a datetime value

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
9 1571
* "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
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
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
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
* "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
Ben
Do a search in your vb help files for datetime customformat
Nov 20 '05 #7
* =?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
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
* "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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
1
by: McGiv | last post by:
Hi, I'm trying to serialise some objects and I've can't get the built in serialisation to output exactly what I want. For the moment I'm implementing the IXmlSerializable interface and doing it...
1
by: Lauchlan M | last post by:
Hi In an ASP.NET application, I am doing the following (dtrData is a data reader that has been loaded with data already): if (dtrData.Read()) { lblEDPresentationTime.Text = (DateTime)...
4
by: darrel | last post by:
I'm binding fileinformation to a repeater and attempting to display the 'lastWriteTime' property as a formatted date. This: <%# DataBinder.Eval(Container.DataItem, "LastWriteTime" %> Gives...
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
2
by: DWalker | last post by:
In Visual Studio (Visual Basic) .NET 2002, I noticed that this: Dim Elapsed as DateTime = Now - Now gives a "compile time" error (error in the IDE), saying that the '-' operator is not...
4
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the...
7
by: sherifffruitfly | last post by:
Hi, God I hate datetime string formatting... How do I get a string of the form "04-Oct-2006", for example, from a DateTime object? Thanks a jillion, cdj
1
by: Untitled | last post by:
I have an application that stores all DateTime inforamtion in UTC. However, this application will be accessed from arround the world. I would like my users to be able to specify their prefered...
3
by: Tim | last post by:
Folks, I'm trying to format a print string so that it reports progress whilst processing a looping structure with a date time stamp appended to the end of the string. This started out life as a...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.