View Single Post
Old 06-29-2009, 09:07 PM   #6 (permalink)
captainmerton
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

Here are the functions:

PHP Code:
<?php

    
function dateDiff($dformat$endDate$beginDate)
    {
    
$date_parts1=explode($dformat$beginDate);
    
$date_parts2=explode($dformat$endDate);
    
$start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);
    
$end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);
    return 
$end_date $start_date;
    }


    function 
getUkDate($date)
    {
    
$date_parts=explode('-'$date);
    return 
$date_parts[2].'-'.$date_parts[1].'-'.$date_parts[0];
    }


    function 
getMysqlDate($date)
    {
    
$date_parts=explode('/'$date);
    return 
$date_parts[2].'-'.$date_parts[1].'-'.$date_parts[0];
    }


    function 
getAge($dob)
    {
    
$todays_date date("Y-m-d");
    
$unixtoday strtotime($todays_date);
    
$unixdob strtotime($dob);
    return 
floor(($unixtoday $unixdob)/31556926);
    }


    function 
validateUkFormat($date)
    {

    
$todays_date date("Y/m/d");
    
$strdate1=$date;

    
//Check the length of the entered Date value 
    
if((strlen($strdate1)<10)OR(strlen($strdate1)>10)){
    throw new 
Exception("Date must be in 'dd/mm/yyyy' format");
    } else {

    
//The entered value is checked for proper Date format 
    
if((substr_count($strdate1,"/"))<>2){
    throw new 
Exception("Date must be in 'dd/mm/yyyy' format");
    } else {
        
$pos=strpos($strdate1,"/");
        
$date=substr($strdate1,0,($pos));
        
$result=ereg("^[0-9]+$",$date,$trashed);
        if(!(
$result)){throw new Exception("Date must be in 'dd/mm/yyyy' format");}
        else{
        if((
$date<=0)OR($date>31)){throw new Exception("Day must be between 1 and 31");}
        }
        
$month=substr($strdate1,($pos+1),($pos));
        if((
$month<=0)OR($month>12)){throw new Exception("Month must be between 1 and 12");}
        else{
        
$result=ereg("^[0-9]+$",$month,$trashed);
        if(!(
$result)){throw new Exception("Date must be in 'dd/mm/yyyy' format");}
        }
        
$year=substr($strdate1,($pos+4),strlen($strdate1));
        
$result=ereg("^[0-9]+$",$year,$trashed);
        if(!(
$result)){throw new Exception("Invalid Year");}

    }
    }


    function 
validateTime($time)
    {
    
$tPieces explode(":",$time);
    
$hour $tPieces[0];
    
$min $tPieces[1];
    
$sec =$tPieces[2];  

    if ((
$hour 0) ||  ($hour 24)) {throw new Exception("Hours must be between 00 and 24");
    } else {
        if ((
$min 0) ||  ($min 60)) {throw new Exception("Mins must be between 00 and 60");
        } else {
            if ((
$sec 0) ||  ($sec 60)) {throw new Exception("Secs must be between 00 and 60");}
        }
    }
    }

    }
?>
captainmerton is offline  
Reply With Quote