Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 17th, 2003, 04:46 AM
Authorized User
 
Join Date: Jun 2003
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default Find the date of the 2nd and 4th Thursday

Hi guys,

I would like to find the date of the 2nd and 4th Thursday of a particular month. Can aynone help please?

Example if I input Now() it will give me 12th and 26th June as the result.

Thanks for your help
 
Old June 17th, 2003, 07:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try this:
1. define a function that takes a month and year number as inputs
2. use the WeekDay function to find what day the 1st of the month is
3. add on the required number of days to move to the first Thursday (e.g if 1st is a Monday, add 3 days)
4. add on a further 7 days to get the 2nd Thursday
5. add on a further 14 days to get to the 4th Thursday

job done
hth
Phil
 
Old June 17th, 2003, 07:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this function GetThursdays. Pass in the date you are interested in and 2 date variables which will return the 2nd and 4th Thursdays.

Code:
Sub GetThursdays(datDate, dat2nd, dat4th)

    'Convert the passed in date to the 1st of the month
    datDate = DateSerial(Year(datDate), Month(datDate), 1)
    'The 2nd Thursday is 7 minus the week day of the date
    'starting from Friday plus 7. For example Monday would
    'be the 4th day, 7 - 4 is 3, 3 + 7 is 10, 10 days from
    'Monday would be the 2nd Thursday
    dat2nd = DateAdd("d", (7 - WeekDay(datDate, vbFriday)) + 7, datDate)
    'The 4th Thursday is the 2nd Thursday plus 14
    dat4th = DateAdd("d", 14, dat2nd)

End Sub
Then in your main ASP code you can do something similar to this:

Code:
Dim Second, Fourth

GetThursdays Now, Second, Fourth

Response.Write "2nd Thursday: " & Second & " 4th Thursday: " & Fourth
This will return the following for any date this month (june 2003)

2nd Thursday: 12/06/2003 4th Thursday: 26/06/2003

I trust this is what you were after.

Regards
Owain Williams
 
Old June 17th, 2003, 07:50 AM
Authorized User
 
Join Date: Jun 2003
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks Owain. Exactly what I needed you saved me a lot of time

Thanks Again

Regards


Ivan Vella





Similar Threads
Thread Thread Starter Forum Replies Last Post
find days per month in a date range rojer MySQL 1 June 5th, 2007 07:36 PM
to find upgrade date priyaram SQL Server 2005 0 February 23rd, 2007 03:43 PM
How to find a date range between another date rang tayvonne Access 2 August 3rd, 2006 09:50 AM
Page 403, 4th para Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 0 June 14th, 2006 05:41 AM
Cannot find code to vb.net 2nd ed..help? lizardnotebk BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 0 September 2nd, 2003 07:17 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.