How to validate date time format must be "yyyy/mm/dd"?

I use VS2003 , C#

In my Layout have a TextBox for user to input Publish Date

the date time format must as "yyyy/mm/dd"

layout like below
Publish Date | TextBox |   ex:2008/09/22

but sometimes user just input 20080922 or 97/09/22 and so on...

how to validate this TextBox must as "yyyy/mm/dd"?

thank you very much

9/24/2008 2:53:05 AM 91979 articles. 4 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 2

you can accept the date as long as it is valid, and then convert it to whatever format you want. Here are 2 options to validate Date

1) The CompareValidator is an option, use Operator=DataTypeCheck and Type=Date for Validator

2) RegularExpressionValidator 

 <asp:TextBox ID="TxtDate" runat="server" MaxLength="10"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegxDate" runat="server" ValidationExpression="(19|20|21)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])" ControlToValidate="TxtDate" ErrorMessage="Enter a valid date e.g (yyyy-mm-dd)"></asp:RegularExpressionValidator>



My Blog

"Don't be afraid to be wrong; otherwise you'll never be right."
9/24/2008 3:07:51 AM

use Javascript Calender to select Date, Check My Post,

please don't forget to check "Answer" if it helps you as it may help other people also.

We All move to our original place.
Don't forget.

Imran Baloch
9/24/2008 3:29:35 AM

Regular Expression: 


for more information take a look of this page:


"Mark As Answer" If my reply helped you --
9/24/2008 4:11:09 AM

You just do one line code for "yyyy/mm/dd" format

 Date.Text = System.DateTime.Now.ToString("yyyy/mm/dd")


You get the date format.

Saiyed Saeed.

---Reveal The Logic---->>
9/24/2008 6:39:27 AM

Just set your one line code

Date.Text = System.DateTime.Now.ToString("yyyy/mm/dd")

you find the yyyy/mm/dd format

Saiyed Saeed.

---Reveal The Logic---->>
9/24/2008 6:41:24 AM

Similar Artilces:

how to get date in "dd/mm/yyyy" using
Hi I have  textbox, while page loads, by default this texbox need to be with today's date in "dd/mm/yyyy"  format... Can anyone suggest how to do this using Thanks aviThanks and  <body>    <form id="form1" runat="server">    <div>    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>    </div>            </form></body...

Problem in Date Comparison with Compare Validator in "dd/MM/yyyy" format
I want to compare dates  for that I have taken two textboxes in which dates are coming through ajax calendar in "dd/MM/yyyy" format I am using compare validator  for comparing with condition that value in textbox2 should be greater than textbox 1  in textbox1 if I enter date suppose"10/03/2008"  and in textbox 2  "11/03/2008" it works fine But in textbox1 if I enter "20/02/2008" and in textbox 2 "11/03/2008" it doesn't works and give message "value in textbox2 should be greater than textbox 1&quo...

How can I return a valid date format when I use a date in "dd-mmm-yyyy" format with US location
When I have Regional setting Location = English (Australia) and Input language = English (Australia) and short date fomat = dd/mmm/yyyy the statement date("01-Jan-2004") returns 1-Jan-2004. When I have Regional setting Location = English (US) and Input language = English (US) and short date fomat = d/m/yyyy the statement date("01-Jan-2004") returns 1/1/1900. How can I get PB8 to return 1/1/2004 when I run the statement date("01-Jan-2004") with US Windows regional settings? Instead of date("29-Jan-2004"), you need to use date(2004, 1, 29). ...

MaskedEditExtender date format problem ("yyyy-MM-dd" with cultureName="sv-SE" doesn't work)
Hi All, I need to create MaskedEditExtender for Sweden date which uses format "yyyy-MM-dd". I have the following code below. CalendarExtender doesn't work with current MaskedEditExtender. Also the validation doesn't work properly. <asp:TextBox ID="txtFSFV" MaxLength="100" style="width:70px" runat="server" /> <asp:HyperLink ID="hplGetCalendar" NavigateUrl="javascript:void(null)" runat="server"> <img src="~/images/calendar.png" runat...

how can i convert the string from "21/12/2005" which is in dd/MM/yyyy format to MM/dd/yyyy
hi all i would like to convert a string that is when user type in the textbox let say "21/12/2005" in dd/MM/yyy and convert to MM/dd/yyyy . how do it do that ?Karen Dim dt As DateTime = txtInput.Text txtOutput.Text = dt.ToString("MM/dd/yyyy")think this should do it Dim strDate(3) as String Dim strDateNewFormat as String strDate = txtDate.text.split("/"c) strDateNewFormat = strDate(1) & "/" & strDate(0) & "/" & strDate(2) ThanksDinuj Nath Try this link for sample code.  Hope this helps.

how to validate date in "dd mmm yyyy" format
Hi, I am trying to validate date in "dd mmm yyyy" format using a RegularExpressionValidator. I am not sure what to use for "ValidationExpression". The date that I would be validating is in this format: "01 Jan 2000". I have to have the space after day and month and I store the whole thing as a string. If anyone has "ValidationExpression" for this particular format, can you please post it ??? Thanks a lot. A great resource for regular expressions is Steve Smith's From there, one of many is ^\d{1,2}\/\d{1,2}\/\d{4}$ Thi...

format Date field in Dataset to "mm/dd/yyyy"
Currently I have a query that is populating a dataset with a date value. Here is my code:  With cmd .CommandText = "SELECT pEff_Dt FROM MyTable WHERE condition1 = condition2" .Parameters.Add(BMItemno) .Connection = SQLConn .CommandType = CommandType.Text End With adapter.SelectCommand = cmd adapter.Fill(dsEffDate) How can I access the only date field passed to my dataset (pEff_Dt) and format it to "mm/dd/yyyy"? Currently is formated to Sat Sep 30 16:31:33 PDT 2006 Any suggestions?  Victor A. Pa...

Daterange Picker Calendar control Without clicking Start Date and End Date Separately ( dd/mm/yyyy-dd/mm/yyyy format
Hello all,  Plz Suggest me the Daterange Picker Calendar control . so that i can select a range of date (after clicking on button javascipt calendar will be executed) and date will appear in the format dd/mm/yyyy-dd/mm/yyyy in listbox (like without cliking for Start Date and End Date Separately)  Swati Jain   Check this: NC... Some of the third party Calendar controls allow multiple selections. If they support the ability to just click on the start and then end dates to form a range, or can limit the u...

US date format dd/mm/yyyy gets converted to mm/dd/yyyy
Dear All,I got an sql query that I pass to sql server as a string. I pass a date as a string in the query and compare it to a date in a table.The trouble is somewhere in the process I get ‘01/04/2006’ turned into ‘04/01/2006’ I do understand mm/dd/yyyy is the US date format. The problem is I pass in dd/mm/yyyy and I compare it to dd/mm/yyyy, however it is dd/mm/yyyy gets compared to mm/dd/yyyy for some reason.I tried the 3 variations below, but none works ok, suggesting that the conversion takes place somewhere #in between’. Can someone tell me how to solve this?<code>Dim myDat...

"Date" mm/dd/yyyy not showing up
Name: Laurie Muntean Email: DogzRpeepL2atohdotrrdotcom Product: Thunderbird Summary: "Date" mm/dd/yyyy not showing up Comments: As of today, the date does not show when the email was received, just shows the "time" received, could care less about the time. I need to know what DAY the email came!!!??? What to do?? Thanks, Laurie Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070914 Firefox/ ...

DataFormatString="{0:dd-MM-yyyy HH:mm}" not displaying military time on remote server
I have a boundfield as follows: <asp:BoundField DataField="PAStatusDate" DataFormatString="{0:dd-MM-yyyy HH:mm}" HeaderText="PA Status Date" HtmlEncode="False" /> When I build this app on my local PC the time portion correctly displays in military time, ie 15:32.When I run this code on my remote server, the time is displayed as 03:32.I have tested variations using h, hh, H, HH and in all instances the remote server displays 3:32 (either with/without leading zero).I tried changing the regional settings on the server to use format ...

Calendar extender format="dd.MM.yyyy"?
 Hi. I have one question about date format in ajax toolkit calendar extender. I want to set the format to "dd.MM.yyyy" because thats the format I need to insert into database. Here is my test code: <%@ Page Language="C#" MasterPageFile="~/master.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="test" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><asp:Content ID="Content1" ...

How to display "dd-mm-yyyy" format from database to text box ?
Hi How to display "dd-mm-yyyy" format from database to text box ? i have written like this but i m not getting the expected op. txtDate.Text= string.Format(ds.Tables[0].Rows[0]["NewsDate"].ToString(),"dd-mm-yyyy");Chandra Dev go through this.... Try like this: txtDate.Text= ds.Tables[0].Rows[0]["NewsDate"].ToString("dd-MM-yyyy"); By the way, I advise that you check for nulls, prior to doing this, just to be safe (especially is NewsDate fields can be null).C# ...

How to convert format of a DateTime object to "yyyy-MM-dd" style
Hi all, i have a date in string data type. i m using Convert.ToDateTime function to convert this string date to DateTime object. When i get this date as a DateTime object it is in "dd-MM-yyyy" format. but i want to convert its format to "yyyy-MM-dd". Can anyone tell me how to convert the format of a DateTime object. I don't want the format with string data type. Please help me. Thanks in advance. once you got your object just do a .ToString("yyyy-MM-dd") on the end of it. Otherwise you'll probably have to change your server settings to be that f...

Web resources about - How to validate date time format must be "yyyy/mm/dd"? -

Resources last updated: 11/20/2015 11:51:43 PM