185 lines
3.4 KiB
PHP
185 lines
3.4 KiB
PHP
<?php
|
|
/* date.inc.php
|
|
* Martin Lenzelbauer, 2006
|
|
*/
|
|
|
|
|
|
# Y-m-d H:i:s => d.m.Y
|
|
//------------------------------
|
|
function datetime2dmy($date){
|
|
//------------------------------
|
|
$d = substr($date,8,2);
|
|
$m = substr($date,5,2);
|
|
$y = substr($date,0,4);
|
|
return "$d.$m.$y";
|
|
}
|
|
|
|
# Y-m-d H:i:s => d.m.Y H:i
|
|
//------------------------------
|
|
function datetime2dmyhi($date){
|
|
//------------------------------
|
|
$d = substr($date,8,2);
|
|
$m = substr($date,5,2);
|
|
$y = substr($date,0,4);
|
|
$h = substr($date, 11,2);
|
|
$i = substr($date,14,2);
|
|
return "$d.$m.$y $h:$i";
|
|
}
|
|
|
|
# creates date from d, m, y
|
|
//------------------------------
|
|
function createDate($d, $m, $y){
|
|
//------------------------------
|
|
$date = "";
|
|
//year
|
|
if(ereg("^[0-9]{4}$", $y)){
|
|
$date .= $y;
|
|
}
|
|
else if(ereg("^[0-9]{2}$", $y)){
|
|
$date .= "20$y";
|
|
}
|
|
else{
|
|
$date .= date("Y");
|
|
}
|
|
$date .= "-";
|
|
//month
|
|
if(!empty($m)){
|
|
if(ereg("^[0-9]{2}$", $m)){
|
|
$date .= $m;
|
|
}
|
|
else{
|
|
$date .= "0$m";
|
|
}
|
|
}
|
|
else{
|
|
$date .= date("m");
|
|
}
|
|
$date .= "-";
|
|
//day
|
|
if(!empty($d)){
|
|
if(ereg("^[0-9]{2}$", $d)){
|
|
$date .= $d;
|
|
}
|
|
else{
|
|
$date .= "0$d";
|
|
}
|
|
}
|
|
else{
|
|
$date .= date("d");
|
|
}
|
|
return $date;
|
|
}
|
|
|
|
# creates date from d, m, y, h, i
|
|
//------------------------------
|
|
function createDatetime($d, $m, $y, $h, $i){
|
|
//------------------------------
|
|
$date = createDate($d, $m, $y);
|
|
$date .= " ";
|
|
//hour
|
|
if(!empty($h)){
|
|
if(ereg("^[0-9]{2}$", $h)){
|
|
$date .= $h;
|
|
}
|
|
else{
|
|
$date .= "0$h";
|
|
}
|
|
}
|
|
else{
|
|
$date .= date("H");
|
|
}
|
|
$date .= ":";
|
|
//minutes
|
|
if(!empty($i)){
|
|
if(ereg("^[0-9]{2}$", $i)){
|
|
$date .= $i;
|
|
}
|
|
else{
|
|
$date .= "0$i";
|
|
}
|
|
}
|
|
else{
|
|
$date .= date("i");
|
|
}
|
|
$date .= ":00";
|
|
return $date;
|
|
}
|
|
|
|
# returns only the given part of the date
|
|
//----------------------------
|
|
function dateGet($date, $format){
|
|
//----------------------------
|
|
switch($format){
|
|
case "Y": return substr($date, 0, 4);
|
|
case "m": return substr($date, 5, 2);
|
|
case "d": return substr($date, 8, 2);
|
|
case "F": return monthname(substr($date, 5, 2));
|
|
}
|
|
}
|
|
|
|
# returns only the given part of the dateime
|
|
//----------------------------
|
|
function datetimeGet($date, $format){
|
|
//----------------------------
|
|
switch($format){
|
|
case "Y": return substr($date, 0, 4);
|
|
case "m": return substr($date, 5, 2);
|
|
case "d": return substr($date, 8, 2);
|
|
case "H": return substr($date, 11, 2);
|
|
case "i": return substr($date, 14, 2);
|
|
case "s": return substr($date, 17, 2);
|
|
}
|
|
}
|
|
|
|
# returns intval of date
|
|
//----------------------------
|
|
function date2int($date){
|
|
//----------------------------
|
|
$int = 0;
|
|
$int += intval(substr($date,8,2));
|
|
$int += 100*intval(substr($date,5,2));
|
|
$int += 10000*intval(substr($date,0,4));
|
|
return $int;
|
|
}
|
|
|
|
# compares two dates
|
|
# -1 if d1 < d2
|
|
# 0 if d1 = d2
|
|
# 1 id d1 > d2
|
|
//----------------------------
|
|
function compareDates($d1, $d2){
|
|
//----------------------------
|
|
$d1 = strtotime($d1);
|
|
$d2 = strtotime($d2);
|
|
if($d1 < $d2){
|
|
return -1;
|
|
}
|
|
if($d1 == $d2){
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
# returns the german name of the given month
|
|
//----------------------------
|
|
function monthname($m) {
|
|
switch($m){
|
|
case "01": return "Januar";
|
|
case "02": return "Februar";
|
|
case "03": return "März";
|
|
case "04": return "April";
|
|
case "05": return "Mai";
|
|
case "06": return "Juni";
|
|
case "07": return "Juli";
|
|
case "08": return "August";
|
|
case "09": return "September";
|
|
case "10": return "Oktober";
|
|
case "11": return "November";
|
|
case "12": return "Dezember";
|
|
}
|
|
return "";
|
|
}
|
|
|
|
|
|
|
|
?>
|