Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

count date

General discussions related to php

Moderators: macek, egami, gesf

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.
superman
New php-forum User
New php-forum User
 
Posts: 36
Joined: Fri Jun 27, 2003 11:54 pm

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 :?:
liquedus
php-forum Active User
php-forum Active User
 
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada

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.
superman
New php-forum User
New php-forum User
 
Posts: 36
Joined: Fri Jun 27, 2003 11:54 pm

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
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

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.
superman
New php-forum User
New php-forum User
 
Posts: 36
Joined: Fri Jun 27, 2003 11:54 pm

Re: e

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

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

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?
superman
New php-forum User
New php-forum User
 
Posts: 36
Joined: Fri Jun 27, 2003 11:54 pm

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

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

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 ;
?>
superman
New php-forum User
New php-forum User
 
Posts: 36
Joined: Fri Jun 27, 2003 11:54 pm

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

http://php.net/mktime
read comments
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

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

ïåæîí! ïîëþáîìó åäèíñòâåííî ïðàâèëüíûé îòâåò...
ÿ â øîêå ÷åãî îíè òóò íàïðåäëîãàëè...
ÎÔÈÃÅÒÜ... îíè áû åù¸ â ðó÷íóþ íà÷àëè ñ÷èòàòü âðåìÿ îò 1970 ãîäà...
ìäÿ... =)
nagash
New php-forum User
New php-forum User
 
Posts: 2
Joined: Tue Jul 08, 2003 7:08 am

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

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

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

HI nagash!
Nice to see you here =))
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

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

yep
me too! =)
nagash
New php-forum User
New php-forum User
 
Posts: 2
Joined: Tue Jul 08, 2003 7:08 am


Return to PHP General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.