Gå til innhold

Finne ut om en dato har hver i år[LØST]


Anbefalte innlegg

Videoannonse
Annonse

lookup the date function, and read the comments. should be something you can use there.

 

this was the second last one there:

mel dot boyce at gmail dot com (06-Apr-2006 12:46)

 

I've been flicking through the comments looking for some succinct date code and have noticed an alarming number of questions and over-burdened examples related to date mathematics. One of the most useful skills you can utilize when performing date math is taking full advantage of the UNIX timestamp. The UNIX timestamp was built for this kind of work.

An example of this relates to a comment made by james at bandit-dot-co-dot-en-zed. James was looking for a way to calculate the number of days which have passed since a certain date. Rather than using mktime() and a loop, James can subtract the current timestamp from the timestamp of the date in question and divide that by the number of seconds in a day:

<?php

$days = floor((time() - strtotime("01-Jan-2006"))/86400);

print("$days days have passed.\n");

?>

Another usage could find itself in a class submitted by Kyle M Hall which aids in the creation of timestamps from the recent past for use with MySQL. Rather than the looping and fine tuning of a date, Kyle can use the raw UNIX timestamps (this is untested code):

<?php

$ago = 14; // days

$timestamp = time() - ($ago * 86400);

?>

Hopefully these two examples of "UNIX-style" timestamp usage will help those finding date mathematics more elusive than it should be.

Lenke til kommentar

Ok, en mindre bra metode, men kan kanskje funke..

 

<?php
$dato = "11/09"; // datoene skrives med null til slutt hvis de er under 10, ellers må 
// du bytte på $dag og $mnd under til "j" og "n"
$dm = explode("/", $dato); // Deler datoen fra d/m til $dm[0] (dato) og $dm[1] (måned)
$dag = date("d");
$mnd = date("m);

if($dm[1] >= $mnd) {
 if($dm[1] == $mnd) {
   if($dm[0] > $dag) {
     $over = 0;
   }
   else{
     $over = 1;
   }
 }
 else {
   $over = 0;
 }
}
else {
 $over = 1;
}

if($over == 1) {
 echo $dato ." har vært ...";
}
else {
 echo $dato ." har ikke vært enda ...";
}
?>

 

Du kan prøve den...

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...