count date

General discussions related to php

Moderators: egami, macek, gesf

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

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: 264
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

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

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: 826
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

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

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: 1240
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Mon Jul 07, 2003 11:54 pm

just use PHP.......
"Sex,Drugs and Rock&Roll " replaced at "Sucks,Bugs and Plug&Play";
Image

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

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: 1240
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Tue Jul 08, 2003 2:54 am

"Sex,Drugs and Rock&Roll " replaced at "Sucks,Bugs and Plug&Play";
Image

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

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 ;
?>

Oleg Butuzov
Last Samuray
Last Samuray
Posts: 824
Joined: Sun Jun 02, 2002 3:09 am

Tue Jul 08, 2003 5:06 am

http://php.net/mktime
read comments

Oleg Butuzov
Last Samuray
Last Samuray
Posts: 824
Joined: Sun Jun 02, 2002 3:09 am

Tue Jul 08, 2003 9:20 pm

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

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

HI nagash!
Nice to see you here =))

Post Reply