Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Calculate last weeks date


Message #1 by "Amy" <sdavis@c...> on Mon, 18 Jun 2001 15:06:51
I am trying to build a function that shows all records for last week and I 

am having problems. any help would be great. For example, if today is 

06/18 or 

any time this week, I want to only see records for 06/10 to 06/16 Sat to 

Sun previous week. This should be dynamic so each week only records from 

the previous week show. I am using the datediff function but I am not 

getting the right records. Thanks for your help.



Amy
Message #2 by "Noumaan Abubakar" <noumaan_abubakar@m...> on Mon, 18 Jun 2001 17:12:46
This is a relatively simple problem, why are you using the datediff 

function? you do not need to use it to find out last weeks date.



Simply use the Date function to obtain today's date, then call the 

function again but this time removing 7 days from it, to obtain last weeks 

date.



for example:



TodaysDate = Date 'assign todays date to the var TodaysDate



LastWeek = Date - 7 'assign last weeks date to the var LastWeek



Then you simply use TodaysDate and LastWeek in your SQL statements to 

obtain the records for that week.



Hope this helps you out



Regards



Noumaan Abubakar











> I am trying to build a function that shows all records for last week and 

I 

> am having problems. any help would be great. For example, if today is 

> 06/18 or 

> any time this week, I want to only see records for 06/10 to 06/16 Sat to 

> Sun previous week. This should be dynamic so each week only records from 

> the previous week show. I am using the datediff function but I am not 

> getting the right records. Thanks for your help.

> 





Message #3 by Elizabeth_Mohr/HR/FCNB/Spgla@s... on Mon, 18 Jun 2001 09:12:52 -0700
Hi Amy,



This code should get you last week's starting and ending dates based on



what date is inputted into the form.  (Assuming you want a Sunday throu

gh

Saturday week).  Hope it helps.



<html>

<body>



<script language=3D"Vbscript">



Function FormatTxtDate()

     Dim strDate

     Dim strFindDay

     Dim strStartDate

     Dim strEndDate

     strDate =3D DateValue(TestDate.txtDate.Value)



     strFindDay =3D WeekDay(strDate)



     If strFindDay =3D 1 Then

          strStartDate =3D (strDate - 7)

               ResultDate.txtStartDate.Value =3D strStartDate

          strEndDate =3D (strDate - 1)

               ResultDate.txtEndDate.Value =3D strEndDate

     Else

          Dim whatsthevalue

          whatsthevalue =3D (7 + strFindDay -1)

          msgbox whatsthevalue

          strStartDate =3D (strDate - (7 + strFindDay - 1))

               ResultDate.txtStartDate.Value =3D strStartDate

          strEndDate =3D (strDate - (1 + strFindDay - 1))

               ResultDate.txtEndDate.Value =3D strEndDate

     End If





End Function



</script>





<form name=3D"TestDate">

Enter Date:<br>

<input type=3D"text" name=3D"txtDate"><br>

<input type=3D"button" onClick=3DFormatTxtDate() value=3D"Find Last Wee

k">

</form>



<form name=3D"ResultDate">

The previous week's starting date is:<br>

<input type=3D"text" name=3D"txtStartDate"><br>

Ending date:<br><input type=3D"text" name=3D"txtEndDate"><br>

</form>





</body>

</html>





                                                                       

                   

                    "Amy"                                              

                   

                    <sdavis@c...        To:     "ASP Databases"       

                   

                    resys.com>           <asp_databases@p...>  

                   

                                         cc:                           

                   

                    06/18/2001           Subject:     [asp_databases] C

alculate last weeks

                    08:06 AM             date                          

                   

                    Please                                             

                   

                    respond to                                         

                   

                    "ASP                                               

                   

                    Databases"                                         

                   

                                                                       

                   

                                                                       

                   







I am trying to build a function that shows all records for last week an

d I

am having problems. any help would be great. For example, if today is

06/18 or

any time this week, I want to only see records for 06/10 to 06/16 Sat t

o

Sun previous week. This should be dynamic so each week only records fro

m

the previous week show. I am using the datediff function but I am not

getting the right records. Thanks for your help.



Amy




  Return to Index