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 May 29th, 2007, 10:05 PM
Authorized User
 
Join Date: Aug 2006
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default total days calculation exclude public holiday

hi all,

is me again. :(nobody reply my last post. but is ok, i have solve it oeldi.now i have another probelem deal with the date.i hope can get some help from u all
i have to textbox to let the user insert the start date and end date and then one checkbox to let the user checked whether they wan to apply the half day leave or not.
after user click submit button, it will calculate the total leave at the backend, then display the applicaiton information again before insert into the DB.
i will prepare another module to let the admin add on when is the public holiday.
the question is:
how can i retrieve the date from the start and end date from the user input and then compare with the public holiday.
if the date they applied involve the public holiday, then the total leave they apply will reduce due to the public holiday.
do u all have any idea?can guide me more.
i feel guilty to bring u all alot of problems as i m a beginner of ASP and also jz learn how to do a system..

hope to hear from u soon.
thank you. :)

 
Old May 29th, 2007, 10:38 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Good day.

NOTE: There is no VBScript date function I am aware of which can find dates within a given date range.

You can achieve this using an SQL statement providing your public holiday dates are stored in a database table, I would reccomend this. How would I do it - set up a table like so:

pulicHoliday (tble name)
ID (an auto incrimenting primary key)
phDate (smallDateTime, no nulls)
inactive (bit, no nulls, default insert of 0)

Throw some dates in there for now which represent public holidays.

Now onsubmit of your user form you will have a start date and an end date, so:

sql = "SELECT count(phDate) FROM pulicHoliday WHERE phDate >= '" & trim(request.form("startDate")) & "' AND phDate <= '" & trim(request.form("finishDate")) & "';"

This will give you the number of days to subtract, to calculate the result:

response.write "You have " & (DateDiff("d", trim(request.form("startDate")), trim(request.form("finishDate"))) - [theResultFromYourQuery] ) & " days leave."

Wind is your friend
Matt
 
Old May 30th, 2007, 04:15 AM
Authorized User
 
Join Date: Aug 2006
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi mat41,
i have write a code to match if the date between start and end date have sat and sun, it will minus 2 days from the total days.
then i write one more code as u teach me to get the total day of public holiday. if got public holiday match with the date then it will minus the days again.
how bout if the public holiday at sat and sun?
how is it work?:(
plz guide me again.
thank you.:)

 
Old May 30th, 2007, 08:27 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

One way would be to add another bit field (no nulls, default value of 0) lets say called satSun. set this to true for all days which fall on a sat or sun. Now change your query to:

sql = "SELECT count(phDate) FROM pulicHoliday WHERE phDate >= '" & trim(request.form("startDate")) & "' AND phDate <= '" & trim(request.form("finishDate")) & "' AND satSun=0;"



Wind is your friend
Matt
 
Old May 30th, 2007, 10:02 PM
Authorized User
 
Join Date: Aug 2006
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi mat41, thanx for ur kind response.i have solve it.thank you very much.but...i have another problem is:

i wan to validate if the start date or end date is same as the public holiday.it will have an alert.
i do it using server side script after submit.
first i call out the record that store the public holiday date.
set rsholy =server.createobject("ADODB.Recordset")
sqlholy = "SELECT holydate FROM publicholiday (DATEPART(w, holydate )<>'7' AND DATEPART(w, holydate )<>'1')"
rsholy.Open sqlholy,conn
then
<% if startdate=rs1("holydate") then %>
<script language="javascript">
alert("start date cannot start on public holiday")
</script>
<%elseif enddate=rs1("holydate") then %>
<script language="javascript">
alert("end date cannot end on public holiday")
</script>
<% end if%>

but it cant work.i got try to loop the recordseet fromthe table public holiday and then match it also no response.
can u all teach me on this?
sql or codiing?
thanx



 
Old May 31st, 2007, 12:44 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

I dont use JS like this, personaly I would do this type of thing on the server side. Anyhow, I supose you can do what you are trying to do

You should research the following two functions:

isDate - (Returns a Boolean value indicating whether an expression can be converted to a date.)

cDate - (Returns an expression that has been converted to a Variant of subtype Date.)

Run these functions on the variables you are comparing to the date type value from the DB. EG:

if cDate(startdate)=cDate(rs1("holydate")) then

if you think you should use a function, use it. To ensure varaibles are the type you want them to be, wrap functions around them.

FYI - you say:
;;;but it cant work.
You should be more precise, what are the exact browser behaviours, errors etc

Wind is your friend
Matt
 
Old June 1st, 2007, 01:00 AM
Authorized User
 
Join Date: Aug 2006
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi mat41, thanx again.i have solve it.
thank you very much.






Similar Threads
Thread Thread Starter Forum Replies Last Post
public article - public articledetails _keysersoze_ BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 September 8th, 2007 08:38 AM
DateDiff calculation for Years, Months & Days demivolt ASP.NET 1.0 and 1.1 Professional 6 October 14th, 2006 12:14 AM
Using a linkdoc to exclude rows geordaa XSLT 1 August 24th, 2006 11:19 AM
Exclude Nodes seanhaggerty XSLT 1 February 3rd, 2005 06:00 AM
Exclude Certain Forms Ben Horne Access VBA 11 March 16th, 2004 03:06 PM





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