"pavan" wrote:
Quote:
Originally Posted by
please help me as i have to validate a text box for date...
>
>
Quote:
Originally Posted by
please help me as i have to validate a text box for date...
>
>
by using a CompareValidator.
<asp:TextBox ID="txtDate" runat="server" />
<asp:CompareValidator ControlToValidate="txtDate" Operator="DataTypeCheck" Type="Date" ErrorMessage="Please enter a valid date" runat="server" ID="cmpValtxtDate" />
<SQL QUERY>
SELECT DATEDIFF(yyyy, Dob, GETDATE()) AS Age
FROM Basic
WHERE (UName = @dotnet.itags.org.UName)This is because using "yyyy" with the DATEDIFF Transact-SQL function to get
the difference in dates subtracts only the year value. One solution is to
simply select the Date from the database, and use the DateTime.Subtract
method to get a TimeSpan indicating the difference between today and the
date from the database. The Years component will give you the age.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Everybody picks their nose,
But some people are better at hiding it.
"eamon" <eamon@.discussions.microsoft.com> wrote in message
news:79683054-0256-40E7-9CF3-5AA59AA927BD@.microsoft.com...
> Im making this stored procedure to return the age of the user to the web
> control but the problem is that DATEPART(). I can only Specify one and i
> need
> the age to to the exact format of mm dd yy but i cant get it into the
> Query
> so it can execute. And when I use the yyyy to return the Age it returns
> the
> age as between 1 - 11 and between 1 - 364 days. So for example the user
> was
> borned 21.11.85. when executed it returns the user is 20 when their 20th
> is
> 4months away.
> <SQL QUERY>
> SELECT DATEDIFF(yyyy, Dob, GETDATE()) AS Age
> FROM Basic
> WHERE (UName = @.UName)
hi
looks like this is a repeated post. here is the answer with the correction
that u made
SELECT DATEDIFF(d, Dob, GETDATE()) / 364 AS Years,
( 12 - ( datepart(m, dob) - datepart(m,getdate()))) % 12 AS Months
FROM Basic
WHERE (UName = @.UName)
--
best Regards,
Chandra
http://chanduas.blogspot.com/
http://www.SQLResource.com/
------------
"eamon" wrote:
> Im making this stored procedure to return the age of the user to the web
> control but the problem is that DATEPART(). I can only Specify one and i need
> the age to to the exact format of mm dd yy but i cant get it into the Query
> so it can execute. And when I use the yyyy to return the Age it returns the
> age as between 1 - 11 and between 1 - 364 days. So for example the user was
> borned 21.11.85. when executed it returns the user is 20 when their 20th is
> 4months away.
> <SQL QUERY>
> SELECT DATEDIFF(yyyy, Dob, GETDATE()) AS Age
> FROM Basic
> WHERE (UName = @.UName)
http://www.databasejournal.com/feat...cle.php/1459151
"eamon" <eamon@.discussions.microsoft.com> wrote in message
news:79683054-0256-40E7-9CF3-5AA59AA927BD@.microsoft.com...
> Im making this stored procedure to return the age of the user to the web
> control but the problem is that DATEPART(). I can only Specify one and i
> need
> the age to to the exact format of mm dd yy but i cant get it into the
> Query
> so it can execute. And when I use the yyyy to return the Age it returns
> the
> age as between 1 - 11 and between 1 - 364 days. So for example the user
> was
> borned 21.11.85. when executed it returns the user is 20 when their 20th
> is
> 4months away.
> <SQL QUERY>
> SELECT DATEDIFF(yyyy, Dob, GETDATE()) AS Age
> FROM Basic
> WHERE (UName = @.UName)
Hi
I am working on asp.net application using vb.net as its language
I want to displaysystem date in a textbox and enter the value into sql database when a button "submit" is clicked
how can do it?when ever this webpage is started the textbox should automatically take the date in the text box and when i click a button submit that date should enter into the sql database
how can i do this?
please help i have an urgent project to be submitted on this plzzzz
You can get the current date by using System.DateTime.Now, however, I suggest you go through the video's and tutorials fromhttp://asp.net/learn to learn how to use ASP.NET before starting on any "urgent" projects.
Hi,
In the Page Load event
first check
if(!ispostback)
then
textbox.text=datetime.now.tostring()
also same for the submit button accept send the value in the insert query rather then textbox
You can also implement it in database level by using getdate()(for SQL server) function in the insert query or stored procedure whatever used by you to insert the value in databaseYou can also implement it in database level by using getdate()(for SQL server) function in the insert query or stored procedure whatever used by you to insert the value in database.
You can also implement it in database level by using getdate()(for SQL server) function in the insert query or stored procedure whatever used by you to insert the value in database.
"please help i have an urgent project to be submitted on this plzzzz"#
sounds like homework..
When ever if the date field is blank i want to raise the Jscript, But it does'nt work.
Only with date i have the problem rest all fields work excellent, if they are blank it does show the javascript message.
Following code is used under the itemcommand of the datagrid.
txtid = e.Item.FindControl("eventid_add")
txtdate = e.Item.FindControl("eventdt_add")
txtref = e.Item.FindControl("eventref_add")
If txtid.Text <> "" And txtdate.Text <> "" And txtref.Text <> "" Then
'do this
Else
'javascript popup
Dim AlertScript As String
AlertScript = "<script language='javascript'>" & _
"alert('Event Date and Reference No. are required!')" & _
"</script>"
Page.RegisterStartupScript("AlertScript", AlertScript)
End If
Thank you very much for the information.Try doing this on the OnItemDataBound event. During OnItemCreated the data is not bound to the datagrid yet, so it is not accessible.
And if it still doesn't work, try to access the data in the datasource(still during OnItemDataBound), not the datagrid; (my example is C#, but you should get the picture)
if (DataBinder.Eval(e.Item.DataItem, "eventdt_add" == DbNull.Value) {
//do your thing
}