Looking for another way to do this

Discussion in 'PHP' started by bozy12v, Apr 23, 2009.

  1. #1
    this means : return the date of the Monday of a specific week from one year
    <?php 
    
    $saptamana=$_POST['sapt']; //astea 2 randuri sunt preluarile de date din formular
    $q=$_POST['anu'];
    $date = new DateTime();
    $date->setDate($q, 1, 1);
    $ziua=$date->format("N");
    /* daca 1 ianuarie e luni */
    if($ziua==1) { 
    $w=$saptamana-1;
    }
    else {
    $w=$saptamana-1;
    if($saptamana==1) {
    $w=$saptamana-2;
    }
    }
    /*daca e luni si vrem sa aflam prima zi a primei sapt - afisam 1 ianuarie */
    if($ziua==1 && $saptamana==1) {
    $rezultatu=$date->format("Y-n-j");
    echo $rezultatu;
    }
    else {
    $date->modify("+$w monday");
    $rezultatu=$date->format("Y-n-j");
    echo $rezultatu;
    }
    
    echo "<br>";
    echo date('d/m/y/W');
    
    ?>
    
    PHP:
    Ignore the comments........
     
    bozy12v, Apr 23, 2009 IP
  2. awatson

    awatson Active Member

    Messages:
    112
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #2
    Not sure what you're trying to do exactly... Do you mean like get the Monday in the 43rd week in the year? Or get the Monday closest to a given date?
     
    awatson, Apr 23, 2009 IP
  3. bozy12v

    bozy12v Active Member

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #3
    yep, the 23rd, 43rd, 33rd ..... or 1st of one given year. The script works fine now (as lonk as i tested it) but i want to know if there's a standard way to get this with php. I get the variables (year and number of the week) from a for via POST in this example ...
     
    bozy12v, Apr 23, 2009 IP