views:

179

answers:

1

I'm in the process of converting a couple of sites up to .net 4.0 and I seem to have a problem with regionalisaion of dates.

This code:

Date.Today.AddDays((Date.Today.DayOfWeek - 1) * -1).ToString()

In .net 3.5 produces: '19/04/2010 00:00:00' but as soon as I change the app pool to 4.0 it produces: '4/19/2010 12:00:00 AM'

Where can I change the setting that governs this?

+1  A: 

I don't think you can try this instead though ...

Date.Today.AddDays((Date.Today.DayOfWeek - 1) * -1).ToString(dd/MM/yyy hh:mm:ss); 

That should format the date as you need it.

Microsoft basically rebuilt quitea lot from the ground up for .net 4.0 ... it's a pain in some areas like this but a real advantage in others.

I sw a guy on another forum that has a huge project consisting of thousands of lines of code that he now has to go find and replace on his datetime.tostring statements.

Best practice has always been that you should specify the format anyway otherwise you get whatever the framework decides.

Hope this helps.

Wardy