count date

General discussions related to php

Moderators: macek, egami, gesf

superman
New php-forum User
New php-forum User
Posts: 36
Joined: Fri Jun 27, 2003 11:54 pm

count date

Postby superman » Sat Jun 28, 2003 7:14 pm

How to count the date from one period to one period. For example, 12-MAY-2003 to 4-Jun-2003, what language should I use and how?
Thank you for your help.

liquedus
php-forum Active User
php-forum Active User
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

Postby liquedus » Sat Jun 28, 2003 7:36 pm

seeing how you posted on http://www.php-forum.com you answered the first part of your question, the second can be done using many ways.

how about using timestamps :?:

superman
New php-forum User
New php-forum User
Posts: 36
Joined: Fri Jun 27, 2003 11:54 pm

Postby superman » Mon Jun 30, 2003 11:22 pm

Then how about excluding the saturday and sunday, it is only count from monday to friday only.

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Tue Jul 01, 2003 12:52 am

try looking at http://www.php.net/date date(w, $timestamp) will produce a numeric representation of the day of the week. 0 (for Sunday) through 6 (for Saturday) you can exclude those

superman
New php-forum User
New php-forum User
Posts: 36
Joined: Fri Jun 27, 2003 11:54 pm

e

Postby superman » Mon Jul 07, 2003 10:16 pm

I use javascript calendar as an input and post to another page to calculate the duration, is it possible to exclude the public holiday? Thank you.

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Re: e

Postby WiZARD » Mon Jul 07, 2003 11:54 pm

just use PHP.......

superman
New php-forum User
New php-forum User
Posts: 36
Joined: Fri Jun 27, 2003 11:54 pm

Postby superman » Tue Jul 08, 2003 1:52 am

I have the code that calculate the duration exclude saturday and sunday, but i dunno how to exclude public holiday. Can somebody help?

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Postby WiZARD » Tue Jul 08, 2003 2:54 am


superman
New php-forum User
New php-forum User
Posts: 36
Joined: Fri Jun 27, 2003 11:54 pm

Postby superman » Tue Jul 08, 2003 3:49 am

This code is work, it take the output from another form as its input to calculate duration. I'm new in php, so can you help me?



<?php
function count_workdays($date1,$date2){
$firstdate = strtotime($date1);
$lastdate = strtotime($date2);
$firstday = date(w,$firstdate);
$lastday = date(w,$lastdate);
$totaldays = intval(($lastdate-$firstdate)/86400)+1;

//check for one week only
if ($totaldays<=7 && $firstday<=$lastday){
$workdays = $lastday-$firstday+1;
//check for weekend
if ($firstday==0){
$workdays = $workdays-1;
}
if ($lastday==6){
$workdays = $workdays-1;
}

}else { //more than one week

//workdays of first week
if ($firstday==0){
//so we don't count weekend
$firstweek = 5;
}else {
$firstweek = 6-$firstday;
}
$totalfw = 7-$firstday;

//workdays of last week
if ($lastday==6){
//so we don't count sat, sun=0 so it won't be counted anyway
$lastweek = 5;
}else {
$lastweek = $lastday;
}
$totallw = $lastday+1;

//check for any mid-weeks
if (($totalfw+$totallw)>=$totaldays){
$midweeks = 0;
} else { //count midweeks
$midweeks = (($totaldays-$totalfw-$totallw)/7)*5;
}

//total num of workdays
$workdays = $firstweek+$midweeks+$lastweek;

}

/*
check for and subtract and holidays etc. here
...
*/

return ($workdays);
} //end funtion count_workdays()

$date1 = "$FromDate";
$date2 = "$ToDate";

echo $Duration ;
?>

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Tue Jul 08, 2003 5:06 am

http://php.net/mktime
read comments

nagash
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Jul 08, 2003 7:08 am
Contact:

Postby nagash » Tue Jul 08, 2003 7:27 am

ïåæîí! ïîëþáîìó åäèíñòâåííî ïðàâèëüíûé îòâåò...
ÿ â øîêå ÷åãî îíè òóò íàïðåäëîãàëè...
ÎÔÈÃÅÒÜ... îíè áû åù¸ â ðó÷íóþ íà÷àëè ñ÷èòàòü âðåìÿ îò 1970 ãîäà...
ìäÿ... =)

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Tue Jul 08, 2003 9:20 pm

íàãàø, òû åùå íå âèäåë êàê îíè ê ìîåìó ñêðèïòó ïðèåáàëèñü, ïðèêèíü çàêàç÷èê óìíûé íî ýò îòàêîå , íî ÷åãîòî îí íå çíàåò... íî ñïðîñèë... çíàåøü êàêàÿ ðåàêöèÿ? îíè ïðåáàëèñü ÷òî
<? à íå <?php ïðèêèíü??? ÿ â øîêå...

ëàíî òóò ñ÷àñ áóäó áóçåòü ÷òî ìû íå íà àíãëèñêîì áàçàðèì è ïîòðåáóþò ïåðåéòè íà èíãëèø...

HI nagash!
Nice to see you here =))

nagash
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Jul 08, 2003 7:08 am
Contact:

Postby nagash » Wed Jul 09, 2003 5:22 pm

yep
me too! =)


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 1 guest

cron