Showing posts with label specify. Show all posts
Showing posts with label specify. Show all posts

Saturday, March 24, 2012

PLEASE HELP GET AGE FROM DATE

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 = @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)

PLEASE HELP GET AGE FROM DATE

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 nee
d
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 = @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 n
eed
> the age to to the exact format of mm dd yy but i cant get it into the Quer
y
> so it can execute. And when I use the yyyy to return the Age it returns th
e
> age as between 1 - 11 and between 1 - 364 days. So for example the user wa
s
> borned 21.11.85. when executed it returns the user is 20 when their 20th i
s
> 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)

Wednesday, March 21, 2012

please help i my code

i cannot navigate to the page i specify, why?

<%@dotnet.itags.org. Control Language="vb" AutoEventWireup="false" Codebehind="Search.ascx.vb" Inherits="SilentBookShop.Search" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<FORM method="post" id="frmSearch" name="frmSearch" action="../WebForm1.aspx">
<TABLE id="Table1" style="WIDTH: 174px; HEIGHT: 90px" cellSpacing="1" cellPadding="1" width="174" align="left" bgColor="#6666ff" border="0">
<TR>
<TD style="COLOR: white; FONT-STYLE: italic; HEIGHT: 15px" align="middle" bgColor="#993300" colSpan="1" rowSpan="1">Search</TD>
</TR>
<TR>
<TD style="HEIGHT: 33px"><SELECT style="WIDTH: 133px">
<OPTION value="" selected>--</OPTION>
<OPTION value="Keyword">Keyword</OPTION>
<OPTION value="Title">Title</OPTION>
<OPTION value="Author">Author</OPTION>
<OPTION value="ISBN">ISBN</OPTION>
</SELECT></TD>
</TR>
<TR>
<TD>
<INPUT style="WIDTH: 132px" type="text" id="searchString" name="searchString">
<INPUT style="WIDTH: 30px; HEIGHT: 22px" type="submit" value="GO"></TD>
</TR>
</TABLE>
</FORM
wen i click at the button, it stays on the same page, it won't go to the page i want.

Thanks!It looks like you're missing some "runat=server" attributes in your elements. This could be contributing to the problem.
Hi,

Because the page that you're going to put your control in already has a form and you can't nest forms.
You should use an asp:button, and Redirect or Transfer from the button's click event.
Alternately, your button's client-side click event could set the action of document.forms[0] to ../WebForm1.aspx and submit.
Let me know if this helps.