Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Non US format DATE

Status
Not open for further replies.

MichMat

Technical User
Dec 9, 2007
8
AU
Hi All,

Im having real problems with the date formats in VB 2005.

Imports System.Globalization
Dim auCulture As CultureInfo = New CultureInfo("en-AU")
Dim TheDate As DateTime

TheDate = DateTime.ParseExact(CurrentDay, "dd/mm/yyyy", auCulture.DateTimeFormat)

Im trying to convert a string in Au format date to a date so that I can perform some date calculations.

I for the life of me cannot piece this together. Could someone please help me with this. I have tried various other methods and everytime I get 12/1/2007 when the String is 1/12/2007 (1st December) with the above example Im getting 1/1/2007. The program recognises that the AU format is right , lists the various formats as correct but doesent actually apply them.

Thanks,
frustrated

Michal
 
I should have added that CurrentDAy is THE string with a date as "1/12/2007".

Is there no edit for a post? I couldnt find it

Michal
 
I'm a UK based user and so use the same date format but I have no problems at all with parsing dates. I have my Regional and Language settings set to English (UK) and the normal Parse method for DateTime works correctly with dd/mm/yyyy format dates with no messing about with Globalization.

Make sure that you're set to English (Australia) and it should all work OK.

Of course if your application is intended for use in regions where the date format is different you will need to take account of that requirement.



Bob Boffin
 
I should add that Visual Studio tends to display dates in US format by default and that if you want to check that the date value really is correct display the Month property instead.

To verify this you can also parse a date entered as '1-dec-2007' and see what VS displays as the Parse method will always get this format right.

Bob Boffin
 
Hi Bob,

I have checked the regional settings and they are all ok as I suspected that they would have been.

The error must be elswhere, in my code. Its very frustrating I have lost many hours trying to figgure out this problem. Having non US settings have always presented this problem. I have never had this much problem in VBA rectifining it before.

All things being right would my code achive what I need it to do ? I have not had the oportunity to encounter a tutorial that explains everything about this feature. Either you get the top half (declarations) or the bottom half but never the complete working example. For people like me, just learning, this is so frustrating.

Michal

 
Hi,

I think I figured it out. Using just plain old CDate I converted the string into a date format

Dim TheDate as Date
Dim CurrentDay as String = "1/12/2007"

TheDate = (CDate(CurrentDay))
MessageBox.Show(TheDate)

The problem was I was looking in the code for the values, which by the way still shows the US date values, BUT everything translates correctly.

Using the above method to find the difference between
1/12/2007 and 3/12/2007 I get the correct 2 days even though (in the code) while running the values are 12/1/2007 and 12/3/2007 which would be 3 months if it wasent correct.

I normaly check the values of strings and other things by stopping the code and see what the value is, obviously this does not work with DATES !!!!!

Hope that this helps someone as well.

Michal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top