I'm having the same problem. My date format is MM/dd/yyyy. How do i find out the date format in my system and change it with code.
If its a date object then you just need to format it using the ToString method.
http://msdn.microsoft.com/en-us/library/system.datetime.tostring.aspx
Code Sample:
using System;
public class DateToStringExample
{
public static void Main()
{
DateTime dateValue = new DateTime(2008, 6, 15, 21, 15, 07);
// Create an array of standard format strings.
string[] standardFmts = {"d", "D", "f", "F", "g", "G", "m", "o",
"R", "s", "t", "T", "u", "U", "y"};
// Output date and time using each standard format string.
foreach (string standardFmt in standardFmts)
Console.WriteLine("{0}: {1}", standardFmt,
dateValue.ToString(standardFmt));
Console.WriteLine();
// Create an array of some custom format strings.
string[] customFmts = {"h:mm:ss.ff t", "d MMM yyyy", "HH:mm:ss.f",
"dd MMM HH:mm:ss", @"\Mon\t\h\: M", "HH:mm:ss.ffffzzz" };
// Output date and time using each custom format string.
foreach (string customFmt in customFmts)
Console.WriteLine("'{0}': {1}", customFmt,
dateValue.ToString(customFmt));
}
}
// This example displays the following output to the console:
// d: 6/15/2008
// D: Sunday, June 15, 2008
// f: Sunday, June 15, 2008 9:15 PM
// F: Sunday, June 15, 2008 9:15:07 PM
// g: 6/15/2008 9:15 PM
// G: 6/15/2008 9:15:07 PM
// m: June 15
// o: 2008-06-15T21:15:07.0000000
// R: Sun, 15 Jun 2008 21:15:07 GMT
// s: 2008-06-15T21:15:07
// t: 9:15 PM
// T: 9:15:07 PM
// u: 2008-06-15 21:15:07Z
// U: Monday, June 16, 2008 4:15:07 AM
// y: June, 2008
//
// 'h:mm:ss.ff t': 9:15:07.00 P
// 'd MMM yyyy': 15 Jun 2008
// 'HH:mm:ss.f': 21:15:07.0
// 'dd MMM HH:mm:ss': 15 Jun 21:15:07
// '\Mon\t\h\: M': Month: 6
// 'HH:mm:ss.ffffzzz': 21:15:07.0000-07:00
Your problem is that your assigning the date in the aspx file and expecting the format to be mm/dd/yyyy when it is probably dd/mm/yyyy so it is blowing up. Are you deploying to a system that uses a different date format?
If so, maybe add the ranges through code manually and assign them using the expected format which is expecting a date object.
Eg.
YourDateValidator.MaximumValue = YourMaxDateTimeObject;
YourDateValidator.MinimumValue = YourMinDateTimeObject;
You should set proper culture for a current thread. DateTime.Parse uses date settings from culture of current thread (btw, I love you, Reflector!):
public static DateTime Parse(string s)
{
return DateTimeParse.Parse(s, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None);
}
where "DateTimeFormatInfo.CurrentInfo" is:
public static DateTimeFormatInfo CurrentInfo
{
get
{
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
if (!currentCulture.m_isInherited)
{
DateTimeFormatInfo dateTimeInfo = currentCulture.dateTimeInfo;
if (dateTimeInfo != null)
{
return dateTimeInfo;
}
}
return (DateTimeFormatInfo) currentCulture.GetFormat(typeof(DateTimeFormatInfo));
}
}
There are a lot of how-to about globalisation, just try to search them ( example of such how-to :))