Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi here i am again asking question. i want to capture academics detail of person hitting website. my form captures visitors graduate/hsc(10+2)ssc(10) information i.e its name of university/10 and 12 board.stream in university(ie ba,bcom,bsc or other)and passing percent in each grade. as well as year of passing.

first question is how to validate date field i.e it should only allow 4 digit int values

second question is there any variable of type as date in sql server(2005) which would only store date and not time because i want to store year of passing in that feild

plz help

thanks
anoop
Posted

Hi,

For first question you can use regularexpression validation control like

expression is \d{4} or you can use your own javascript method

For second question ,upto my knowledge there is no specific datatype for only date format.

We pass only date to that column after that we retrieve the value and cut only date from that value.
by default it takes time as like ... 12:00:00 in format

so no problem in it we can manipulate while reading data from database


All the Best
 
Share this answer
 
Hi
For the second question

No, there is no "date" data type in sql server 2005, but introduced in SqlServer 2008.

When you store try to save Date part of DateTime..
 
Share this answer
 
you do not want the time (hh:mm:ss) portion from the query then use convert function

---- Retrieve info from table and return date (datatype) value
-----as character mm/dd/yyyy

select CONVERT(varchar(10),DateTimeColumnName,101) as MyDate
from TableName

OR

select CONVERT(varchar(10),GETDATE(),101) as charSystemDate

Validate date (datatype with T-SQL)

For Instance T-SQL via Store procedure
---------- Begin of Proc----------------------
CREATE PROC uspStoreData
@dtDate varchar(50)
as

DECLARE @dtRealDate datetime

IF ISDATE(@dtDate)=1
BEGIN
SET @dtRealDate = CONVERT(datetime,@dtDate)
END

----- Insert into tableName (DateTimeColumnName) values(@dtRealDate)
OR
---- update tableName set DateTimeColumnName=@dtRealDate where clause here

---------- End of Proc----------------------

-----------------------------------------------------
With ASP.NET, C#, VB.NET:
-----------------------------------------------------
if you need a good tools to validate input from a form then
download the free tools that a friend of mine put together that works
with ASP.NET, C#, VB.NET (Windows form and Web Forms
http://www.netstair.com/download/ncTools/ncTools-Lib.zip

---- Convert to Date/Time yyyy-mm-dd hh:mm:ss (Once downloaded use as follow)
ncTools.oUtilities oObj = new ncTools.oUtilities()
DateTime dtDateInputed
if (oObj.IsDate(textbox1.text))
{
dtDateInputed = Convert.DateTime(textbox1.text);
}
----- Convert to String mm/dd/yyyy
string strDateInputed = Convert.DateTime(textbox1.text).ToShortDateString();



Good Luck
Al
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900