3

Date time format is working fine when it is running in local server but the same is not working fine when it is uploaded to server.

in localhost

02-02-2014

in server

2-2-2014

I want localhost format in server also

Lingraj Gowda
  • 159
  • 1
  • 1
  • 12
  • 2
    See http://stackoverflow.com/questions/300841/how-do-you-globally-set-the-date-format-in-asp-net – road242 Feb 22 '14 at 10:47

2 Answers2

0

You should provide some sample code to help define the context. But keeping things as simple as possible...

A date is a date, regardless of the host computer and its locale, so if you want to disregard the host computer locale, which affects things like how dates are expressed, you might want to consider using a Custom Date Format.

// Display the date using a custom date format
DateTime thisDate = new DateTime(2008, 3, 15);
Console.WriteLine(thisDate.ToString("dd-MM-yyyy"));  // Displays 15-03-2008
Console.WriteLine(thisDate.ToString("dd MMM yyyy")); // Displays 15 Mar 2008
Nigel Belham
  • 463
  • 3
  • 12
  • 1
    Thanks for your reply sir, i am not getting any error in datetime format. as you said while the date is saving into database it is getting saved as 07/02/2014 but while retriving the same date it is getting retrived as 7/2/2014 as it is throwing error while updating the same form. – Lingraj Gowda Feb 22 '14 at 11:02
  • 1
    That is normal behaviour. A formatted date such as 07/02/2014 (I really don't like dates expressed like this because the format is ambiguous - is it 7 Feb or 2 Jul? - that date will be rendered differently depending upon the locale of the host computer you see) when stored into the DB Engine will be stored as a date without any form of formatting, so when you retrieve the stored date it will need to be formatted using the format string that you wish to use. e.g. uiDateLabel.Text = storedDate.ToString("dd MMM yyyy") – Nigel Belham Feb 22 '14 at 11:24
0

Perhaps your date formatting is not the same

DateTime time = new DateTime(2014, 02, 02);

string format = "mm-dd-yy";
Console.WriteLine(time.ToString(format)); //00-02-14

format = "M-d-yy";  
Console.WriteLine(time.ToString(format)); //2-2-14
hdoghmen
  • 3,175
  • 4
  • 29
  • 33