Click here to Skip to main content
15,892,746 members
Articles / Web Development / IIS

Date control with support for languages and different date formats

Rate me:
Please Sign up or sign in to vote.
4.14/5 (11 votes)
31 May 20054 min read 93.6K   713   47  
Using .NET's System.Globalization class for retrieving month names in forgein lanaguages, and the DateTimeFormatInfo for keeping your dates the correct way around.
<%@ Register TagPrefix="cc1" Namespace="i386.UI" Assembly="DropDownDateTime" %>
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="CodeProjectDemo.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>WebForm2</title>
		<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
		<meta content="C#" name="CODE_LANGUAGE">
		<meta content="JavaScript" name="vs_defaultClientScript">
		<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
	</HEAD>
	<body MS_POSITIONING="GridLayout">
		<form id="Form1" method="post" runat="server">
			<font face="Verdana" size="-1"><b>German, short month text, output dd/MM/yyyy</b><br>
				<cc1:dropdowndatetime  id="DropDownDateTime2" runat="server" YearsForward="2" YearsBack="10"
					Culture="de-DE" MonthFormat="MMM" ></cc1:dropdowndatetime><br>
				<br>
				<b>French, output dd-MM-yyyy<asp:label id="Label1" style="Z-INDEX: 102; LEFT: 368px; POSITION: absolute; TOP: 80px" runat="server"></asp:label></b><br>
				<cc1:dropdowndatetime  id="DropDownDateTime1" runat="server" YearsForward="5" YearsBack="60"
					Culture="fr-FR" DateFormat="dd-MM-yyyy" ></cc1:dropdowndatetime><br>
				<br>
				<b>Spanish, output yyyyMMdd</b><br>
				<cc1:dropdowndatetime  id="DropDownDateTime3" runat="server" YearsForward="2" YearsBack="10"
					Culture="es-ES" DateFormat="yyyyMMdd" Value="19990506"></cc1:dropdowndatetime><br>
				<br>
				<b>US, output MM/dd/yyyy in Debugmode</b><br>
				<cc1:dropdowndatetime DebugMode="true" id="Dropdowndatetime4" runat="server" YearsForward="2" YearsBack="10"
					Culture="en-gb" DateFormat="MM/dd/yyyy" Value="11/02/2005"></cc1:dropdowndatetime>
				<br>
				<asp:button id="Button1" runat="server" Text="Show Output"></asp:button>
		</form>
		</FONT>
	</body>
</HTML>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
Austria Austria
Programmer, Cook, Photographer I guess that's me.

http://www.i386.com

http://blog.glyons.at

Comments and Discussions