Пример #1
0
function form_dt($n, $dt = '0000-00-00 00:00:00')
{
    global $curr;
    $o = '';
    $yb = $curr['year'] - 10;
    $ye = $curr['year'] + 2;
    $y0 = 0;
    $m0 = 0;
    $d0 = 0;
    $yf = 0;
    $mf = 0;
    $df = 0;
    $hf = 0;
    while (1) {
        if ($n[0][0] == '@') {
            $yf = 1;
            $n[0] = substr($n[0], 1);
            continue;
        }
        if ($n[0][0] == '!') {
            $y0 = 1;
            $n[0] = substr($n[0], 1);
            continue;
        }
        break;
    }
    $yx = explode(';', $n[0]);
    $y = $yx[0];
    if (isset($yx[1])) {
        $yb = $yx[1];
    }
    if (isset($yx[2])) {
        $ye = $yx[2];
    }
    while (1) {
        if ($n[1][0] == '@') {
            $mf = 1;
            $n[1] = substr($n[1], 1);
            continue;
        }
        if ($n[1][0] == '!') {
            $m0 = 1;
            $n[1] = substr($n[1], 1);
            continue;
        }
        break;
    }
    $m = $n[1];
    while (1) {
        if ($n[2][0] == '@') {
            $df = 1;
            $n[2] = substr($n[2], 1);
            continue;
        }
        if ($n[2][0] == '!') {
            $d0 = 1;
            $n[2] = substr($n[2], 1);
            continue;
        }
        break;
    }
    $d = $n[2];
    if (isset($n[3])) {
        if ($n[3][0] == '@') {
            $hf = 1;
            $n[3] = substr($n[3], 1);
        }
        $h = $n[3];
        $i = $n[4];
        $s = $n[5];
    }
    $o .= '<select name="' . $d . '"' . ($df ? ' autofocus' : '') . '>';
    if ($d0) {
        $o .= '<option value="0">- -';
    }
    $dte = datee($dt, 'd');
    for ($j = 1; $j < 32; $j++) {
        $o .= '<option value="' . $j . '"' . ($j == $dte ? ' selected' : '') . '>' . substr('00' . $j, -2, 2);
    }
    $o .= '</select>';
    $o .= ' <select name="' . $m . '"' . ($mf ? ' autofocus' : '') . '>';
    if ($m0) {
        $o .= '<option value="0">- -';
    }
    $dte = datee($dt, 'm');
    for ($j = 1; $j < 13; $j++) {
        $o .= '<option value="' . $j . '"' . ($j == $dte ? ' selected' : '') . '>' . substr('00' . $j, -2, 2);
    }
    $o .= '</select>';
    $o .= ' <select name="' . $y . '"' . ($yf ? ' autofocus' : '') . '>';
    if ($y0) {
        $o .= '<option value="0">- - - -';
    }
    $dte = datee($dt);
    for ($j = $yb; $j <= $ye; $j++) {
        $o .= '<option value="' . $j . '"' . ($j == $dte ? ' selected' : '') . '>' . $j;
    }
    $o .= '</select> г.';
    if (isset($n[3])) {
        $o .= ' <select name="' . $h . '"' . ($hf ? ' autofocus' : '') . '>';
        $dte = datee($dt, 'h');
        for ($j = 0; $j < 24; $j++) {
            $o .= '<option value="' . $j . '"' . ($j == $dte ? ' selected' : '') . '>' . substr('00' . $j, -2, 2);
        }
        $o .= '</select>';
        $o .= ' <select name="' . $i . '">';
        $dte = datee($dt, 'i');
        for ($j = 0; $j < 60; $j++) {
            $o .= '<option value="' . $j . '"' . ($j == $dte ? ' selected' : '') . '>' . substr('00' . $j, -2, 2);
        }
        $o .= '</select>';
        $o .= ' <select name="' . $s . '">';
        $dte = datee($dt, 's');
        for ($j = 0; $j < 60; $j++) {
            $o .= '<option value="' . $j . '"' . ($j == $dte ? ' selected' : '') . '>' . substr('00' . $j, -2, 2);
        }
        $o .= '</select>';
    }
    return $o;
}
Пример #2
0
function datediffy($date_a, $date_b = NULL)
{
    if (!$date_b) {
        global $curr;
        $date_b = $curr['date'];
    }
    $years = datee($date_b) - datee($date_a) - 1;
    if (datee($date_b, 'm') > datee($date_a, 'm')) {
        $years++;
    } elseif (datee($date_b, 'm') == datee($date_a, 'm') && datee($date_b, 'd') >= datee($date_a, 'd')) {
        $years++;
    }
    return $years;
}