Jump to content

mktime function


jimfog

Recommended Posts

Is there a way i can get the monday of a each week with the mktime function? I am not talking about a specific Monday but for the monday of each week. So far, i have achieved that with this:

$thismonday=date("d",strtotime("previous Monday"));

Can the above outcome be achieved with mktime?

Link to comment
Share on other sites

In my example I gave you

$prevMondayCalc= strtotime ( 'last Monday' , strtotime ( $arg ) ) ;$prevtMonday = date("d-m-Y", $prevMondayCalc);$nextMondayCalc= strtotime ( 'next Monday' , strtotime ( $arg ) ) ;$nextMonday = date("d-m-Y", $nextMondayCalc);

will give you the previous and next monday, whatever current date is shown.

Link to comment
Share on other sites

In my example I gave you
$prevMondayCalc= strtotime ( 'last Monday' , strtotime ( $arg ) ) ;$prevtMonday = date("d-m-Y", $prevMondayCalc); $nextMondayCalc= strtotime ( 'next Monday' , strtotime ( $arg ) ) ;$nextMonday = date("d-m-Y", $nextMondayCalc);

will give you the previous and next monday, whatever current date is shown.

Well, i have already done the above, the problem is this,now-let me explain. In Outlook, when you go to week view what you get is the week from the beginning of it till the end of it(for example, 20-26 February) So the code above(or a variation of it-since "Next Sunday" must be added instead of "next Monday") just, aids in the navigation. Now i have problem in printing in the browser the 20-26 February, and from this point the above code will take control by navigating from week to week. Newdate will not do as it defaults to today's day($newdate = date("d-m-Y");-if you recall.). I tried this first-but it did not work:
date("d", strtotime("previous monday"))

The above does output 20 February, but i when i click this link:

<li><a href=" ' . $_SERVER["PHP_SELF"] ."?newdate=". [color=#000000][size=2]$prevtMonday[/size][/color] . '">previous Week</a><li>

i get again 20 February, however, on 2nd click, i get 13 February. This happens because $newdate = date("d-m-Y");, which is today's date. So, on first click newdate goes from 23 feb to 20. So , the user must click TWICE to go to 13 February Do you understand what the problem is? Sorry if it is a little confusing.

Link to comment
Share on other sites

I managed to do it, only time will tell if it proves functional/practical:

$newdate = date("d-m-Y"); $newdate1="previous monday";$leapYear = date("L");setPrevNextDates($newdate,$newdate1);    if (isset($_GET['newdate'])) {  	  $newdate =$_GET['newdate'];	 setPrevNextDates($newdate,$newdate1 );}elseif (isset($_GET['newdate1'])){$newdate=$newdate1 =$_GET['newdate1']; setPrevNextDates($newdate,$newdate1);}  function setPrevNextDates($arg,$arg1)								{	 global  $nextDay, $prevDay,$begweek,$endweek,			 $nextMonth, $timestamp,$cYear,$thismonth ,			 $maxday, $prevMonth,$startday, $nextYear,			 $prevYear,$thismonday,$newdate1, $leapYear;		 $prevDayCalc = strtotime('-1 day', strtotime($arg));	 $prevDay = date("d-m-Y", $prevDayCalc);	 $nextDayCalc = strtotime('+1 day', strtotime($arg));	 $nextDay = date("d-m-Y", $nextDayCalc);	 $prevMonCalc = strtotime('-1 month', strtotime($arg));	 $prevMonth = date("d-m-Y", $prevMonCalc);	 $nextMonCalc = strtotime('+1 month', strtotime($arg));	 $nextMonth = date("d-m-Y", $nextMonCalc);	 $prevYearCalc = strtotime('-1 year', strtotime($arg));	 $prevYear = date("d-m-Y", $prevYearCalc);	 $nextYearCalc = strtotime('+1 year', strtotime($arg));	 $nextYear = date("d-m-Y", $nextYearCalc);		 $begweekCalc=strtotime ( 'previous monday' , strtotime ( $arg1 ) ) ;	 $begweek=date("d-m-Y", $begweekCalc);	 $endweekCalc=strtotime ( 'next sunday' , strtotime ( $arg ) ) ;	 $endweek=date("d-m-Y", $endweekCalc);  		 $LeapYearCalc = strtotime($arg);	 $leapYear = date("L", $LeapYearCalc);	  	if ($leapYear == 1 && date("m", strtotime($arg)) == 2 && date("d", strtotime($arg)) == 29) {		 $prevYearCalc = strtotime('-1 day', strtotime($prevYear));		 $prevYear = date("d-m-Y", $prevYearCalc);		 $nextYearCalc = strtotime('-1 day', strtotime($nextYear));		 $nextYear = date("d-m-Y", $nextYearCalc);	 }} function output_week() {	 global  $monthNames1, $newdate,$begweek,$endweek,$newdate1,$startday,$thismonday;	  echo $newdate;  	  //στο παρακάτω θέλουμε τόσο να ξεκινάει απο την Δευτέρα ο μήνας οσο ΚΑΙ ΑΠΟ ΕΚΕΙΝΟ ΤΟ ΧΡΟΝΙΚΟ ΣΗΜΕΙΟ ΝΑ πηγαίνει στην προηγούμεη εβδομάδα	 echo '<ul id="days">			<li><a href=" ' . $_SERVER["PHP_SELF"] ."?newdate1=". $begweek . '">previous week</a><li>			<li>'. date("d", strtotime($newdate1)). $monthNames1[date("n", strtotime($newdate)) - 1] . '  ' . date("Y", strtotime($newdate)).'</li>						<li><a href=" ' . $_SERVER["PHP_SELF"] ."?newdate1=".$endweek. '">next Week</a><li>		 </ul>';	

I am awaiting your comment-of course is hlafway where i want it to be, but the logic is the same.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...