Location: PHPKode > projects > EmploiNet : a timetable web manager > EmploiNet/v0.8.0/date.php3
<?
  function moisx ($x,$year) {
  $aujourdhui= mktime (0,0,0, date ("m"), date("d"), $year);
  $jour_courant= (int) strftime ("%j", $aujourdhui);
  $jour_x= mktime (0,0,0, date ("m"), date ("d") - $jour_courant + $x, $year);
  $x_mois= (int) strftime("%m", $jour_x);
  return $x_mois;   } 
?>

<?
  function jourmoisx ($x,$year) {
  $aujourdhui= mktime (0,0,0, date("m"),date("d"), $year);
  $jour_courant= (int)strftime("%j", $aujourdhui);
  $jour_x= mktime (0,0,0, date("m"),date("d")-$jour_courant+$x, $year);
  $x_jourmois= (int)strftime("%d", $jour_x);
  return $x_jourmois;   }  
?>

<?   
  function numerosemainex($x,$year) {
  $aujourdhui= mktime (0,0,0, date("m"),date("d"), $year);
  $jour_courant= (int)strftime("%j", $aujourdhui);
  $jour_x= mktime (0,0,0, date("m"),date("d")-$jour_courant+$x, $year);
  $x_numerosemaine= strftime("%W", $jour_x);
  return $x_numerosemaine;    } 
?>


<?
// Formate la date a partir du numero de jour et du numero de semaine
function weekAndDayToDate($jour,$semaine,$connection)
{
	$result = mysql_query("SELECT * FROM global",$connection);
	$a_record = mysql_fetch_row($result);
	$annee_ref = $a_record[1];

	$nb_jours=weekToDay($semaine,$connection)+$jour-1;
	$trans = mysql_query("SELECT FROM_DAYS($nb_jours)");
    $result_trans = mysql_fetch_row($trans);
    $trans2 = mysql_query("SELECT DATE_FORMAT(\"$result_trans[0]\",'%d/%m')");
	$result_trans2 = mysql_fetch_row($trans2);

	return $result_trans2[0]."/".$annee_ref;
}

// Determine le numero du premier jour de la semaine indiquee
function weekToDay($s_semaine,$connection)
{
	// Recuperation de l'annee de reference et de la semaine de reference (premiere semaine de l'annee)
	$result = mysql_query("SELECT * FROM global",$connection);
	$a_record = mysql_fetch_row($result);
	$semaine_ref = $a_record[0];
	$annee_ref = $a_record[1];

	// Calcul du numero du premier jour de l'annee vis a vis d'une date absolue (1/1/70)
	if ($s_semaine<$semaine_ref) 
	{
		$request = "SELECT TO_DAYS('".($annee_ref+1)."-01-01')";
		$result = mysql_query($request,$connection);
	}
	else 
	{
		$request = "SELECT TO_DAYS('".$annee_ref."-01-01')";
		$result = mysql_query($request,$connection);
	}
	$a_record = mysql_fetch_row($result);
	$jour_ref = $a_record[0];

	// Calcul du numero du premier jour de l'annee dans la semaine (1 = dimanche ...)
	if ($s_semaine<$semaine_ref) 
	{
		$request = "SELECT DAYOFWEEK('".($annee_ref+1)."-01-01')";
		$result = mysql_query($request,$connection);
	}
	else 
	{
		$request = "SELECT DAYOFWEEK('".$annee_ref."-01-01')";
		$result = mysql_query($request,$connection);
	}
	$a_record = mysql_fetch_row($result);

	// Calcul du numero du premier jour de la semaine donnee vis a vis d'une date absolue
	return($jour_ref+($s_semaine-1)*7+(2-$a_record[0]));
}

// Determine le numero du mois de la semaine indiquee
function weekToMonth($s_semaine,$connection)
{
	$day = weekToDay($s_semaine,$connection);
	$trans = mysql_query("SELECT FROM_DAYS($day)");
    $result_trans = mysql_fetch_row($trans);
   	$trans2 = mysql_query("SELECT DATE_FORMAT(\"$result_trans[0]\",'%m')");
    $result_trans2 = mysql_fetch_row($trans2);
	return $result_trans2[0];
}

?>
Return current item: EmploiNet : a timetable web manager