Search result for 'php time conflicts'
(0.0166120529175 seconds)
56 pages : 1 2 3 4 5 6 7 8 9 10 11 Next › Last»

leonelsantos/Time Conflict Check ( PHP)

/*
		
	check if time overlaps
	parameters should be same date format
		
*/
function intersectCheck($from, $from_compare, $to, $to_compare){
	$from = strtotime($from);
	$from_compare = strtotime($from_compare);
	$to = strtotime($to);
	$to_compare = strtotime($to_compare);
	$intersect = min($to, $to_compare) - max($from, $from_compare);
		if ( $intersect < 0 ) $intersect = 0;
		$overlap = $intersect / 3600;
		if ( $overlap <= 0 ):
			// There are no time conflicts
			return TRUE;
			else:
			// There is a time conflict
			// echo '<p>There is a time conflict where the times overlap by ' , $overlap , ' hours.</p>';
			return FALSE;
		endif;
}

mike-tempest/Rather than using $(document).ready / alternative no conflict ( jQuery)

jQuery(function( $ ){
    //Insert your javascript code here

});

Hello,

I have been developing with jQuery for just over a year now, I thought I would share something with you that I have found pretty time saving over the past few months.

If you have ever had javascript conflicts due to several different javascript libraries being used you will understand the need for using this method.

Rather than using the documented $(document).ready method of starting any javascript functionality on document load. I recommend that you give the alternative shown below. This is due to the common conflict between Javascript libraries using the $ symbol. By writing your document ready in this way, any $ symbols within this declaration will be ignored by all other javascript libraries.

Meaning you will no longer need to use the no conflict method of solving the same problem

thesmu/clear out jquery to prevent conflicts ( PHP)

/*
 * WordPress Sample function and action
 * for loading scripts in themes
 */
 
// Let's hook in our function with the javascript files with the wp_enqueue_scripts hook 

add_action( 'wp_enqueue_scripts', 'wpcandy_load_javascript_files' );

// Register some javascript files, because we love javascript files. Enqueue a couple as well 

function wpcandy_load_javascript_files() {

wp_deregister_script( 'jquery');  

wp_register_script( 'jquery', get_template_directory_uri().'/js/jquery-1.8.2.min.js', array(), '1.8.2', false );  

wp_enqueue_script('jquery');


wp_register_script( 'jquery.flexslider', get_template_directory_uri().'/js/jquery.flexslider.js', array('jquery'), '1.7', false );  

wp_enqueue_script('jquery.flexslider');




}

goes in the functions file

mburica/Seconds to human readable time ( PHP)

$time = time() - $time;
        
        $points = array(
            'year'     => 31556926,
            'month'    => 2629743,
            'week'     => 604800,
            'day'      => 86400,
            'hour'     => 3600,
            'minute'   => 60,
            'second'   => 1
        );
        
        foreach($points as $point => $value)
        {
            if($elapsed = floor($time/$value) > 0)
            {
                $s = $elapsed>1?'s':'';
                $timestamp = "$elapsed $point$s";
                break;
            }
        }

Takes a # of seconds and converts it to human readable format. If happened within seconds-years.

pruntrut/Format time from mysql ( Other)

echo date('H:i',strtotime($time));

vagrantradio/Basic PHP Date and Time Functions ( PHP)

function strip_zeros_from_date( $marked_string = "" ){
		//Remove any Zeros in the date
		$no_zeros = str_replace('*0', '', $marked_string );
		//Remove the Asterik regardless of no Zeros
		$cleaned_string = str_replace('*', '', $no_zeros );
		
		return $cleaned_string;
	}

	//Number of seconds since January 1, 1970
	echo $time = time();
	echo "<br /><br />";

	//Make a timestamp using mktime( $hr, $min, $sec, $mo, $day, $yr )
	echo $mktime =  mktime( 2, 30, 45, 10, 1, 2009 );
	echo "<br /><br />";

	//Convert this date to a string
	echo $date = strtotime("September 15, 2000");
	echo "<br /><br />";			

	//Convert Last Monday to a String
	echo $last_monday = strtotime("last Monday");
	echo "<br /><br />";			

	//Convert 1 day from today to a String
	echo $tomorrow = strtotime("+1 day");
	echo "<br /><br />";			

	//Check if this date is valid (February 31st)
	echo $valid_date = checkdate( 2, 31, 2000 ) ? "true" : "false";
	echo "<br /><br />";			
	
	//Format a Unix Timestamp into something human readable (http://php.net/manual/en/function.strftime.php)
	//The asterik is neat little hack that will help us build a helper function
	echo strip_zeros_from_date( strftime( "*%m/*%d/%y", $last_monday ) );

	echo "<br /><br />";
	
	//Format your date in PHP for MySQL
	$dt = time();
	$mysql_datetime = strftime("%Y-%m-%d %H:%M:%S", $dt);
	echo $mysql_datetime;

Self Explanatory

kotnik/php code exution time ( PHP)

// put this at the top of the page
   $mtime = microtime();
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $starttime = $mtime;

// put other code and html in here

// put this code at the bottom of the page
   $mtime = microtime();
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $endtime = $mtime;
   $totaltime = ($endtime - $starttime);
   echo "This page was created in ".$totaltime." seconds";

This code is based on the ASP script posted by Lio. It will determine the time taken for a php script to execute correct to 0.000000000000001 seconds.

fazlee/e-solat php script ( PHP)

<?php
/* --------------------------------------------
	Malaysia Prayer time for GeekTools
	Data source : http://www.e-solat.com.my
	Author		: Fazlee Rezuan [fazlee@gmail.com]
 ----------------------------------- */
// Get the page
$value = strip_tags(file_get_contents('http://www.e-solat.gov.my/solat.php?kod=sgr01&amp;lang=BM'));

// Remove unwanted strings &amp; values, cleaning html tags and spaces
$stripped_value = preg_replace('/\s+/','',$value);
$waktu 			= explode('WaktuSolat', str_replace('&amp;nbsp;', ' ', $stripped_value));
$waktu1 		= ereg_replace("[^0-9: ]", "", $waktu[1]);
$solat 			= explode(' ', str_replace('       ',' ', $waktu1));

// Print out prayer time
echo "Subuh: ".@date('g:ia', @strtotime($solat[2]))."\t\tZuhur: ".@date('g:ia', @strtotime($solat[4])).
		"\t\tAsar: ".@date('g:ia', @strtotime($solat[5]))."\nMaghrib: ".@date('g:ia', @strtotime($solat[6]))."\t\tIsyak: ".@date('g:ia', @strtotime($solat[7]));

?>

The purpose of this code is to grab information from e-solat.gov.my and get payer exact time. I use this code with GeekTools.

xtheonex/Convert date/time into a readable format. ( PHP)

function dateConvert($old_date, $layout) { 
	$date = ereg_replace('[^0-9]', '', $old_date);
	$date_year = substr($old_date,0,4);
	$date_month = substr($old_date,5,2);
	$date_day = substr($old_date,8,2);
	$date_hour = substr($old_date,11,2);
	$date_minute = substr($old_date,14,2);
	$date_second = substr($old_date,17,2);
	$new_date = date($layout, mktime($date_hour, $date_minute, $date_second, $date_month, $date_day, $date_year));
	return $new_date;
}

A quick, usefull function which i use to convert a date/time string pulled from MySQL, into a readable format.

noorahmad/Date to time time to date in PHP ( PHP)

// date to time
$time = strtotime($date);



// time to date
function time_to_date($add){
	$time =  $add;
	$date = getdate($time);
	$day = $date['mday'];
	$mon = $date['mon'];
	$year = $date['year'];
	$date = $year."-".$mon."-".$day;
	return $date;
}
echo time_to_date($time);


jknight42/PHP display date: year, month, day, time, etc. ( PHP)

<?php echo date("l"); ?>  // Day of the week, ie: Monday
<?php echo date("Y"); ?>  // Year, ie: 2012
<?php echo date("F j, Y, g:i a"); ?>  // Date and time, ie: March 10, 2001, 5:16 pm

Just a few quick functions to display the date in PHP.

bitstream/nice time duration in php ( PHP)

/**
 * A function for making time periods readable
 *
 * @author      Aidan Lister <aidan@php.net>
 * @version     2.0.1
 * @link        http://aidanlister.com/2004/04/making-time-periods-readable/
 * @param       int     number of seconds elapsed
 * @param       string  which time periods to display
 * @param       bool    whether to show zero time periods
 */
function time_duration($seconds, $use = null, $zeros = false)
{
    // Define time periods
    $periods = array (
        'years'     => 31556926,
        'Months'    => 2629743,
        'weeks'     => 604800,
        'days'      => 86400,
        'hours'     => 3600,
        'minutes'   => 60,
        'seconds'   => 1
        );
 
    // Break into periods
    $seconds = (float) $seconds;
    $segments = array();
    foreach ($periods as $period => $value) {
        if ($use &amp;&amp; strpos($use, $period[0]) === false) {
            continue;
        }
        $count = floor($seconds / $value);
        if ($count == 0 &amp;&amp; !$zeros) {
            continue;
        }
        $segments[strtolower($period)] = $count;
        $seconds = $seconds % $value;
    }
 
    // Build the string
    $string = array();
    foreach ($segments as $key => $value) {
        $segment_name = substr($key, 0, -1);
        $segment = $value . ' ' . $segment_name;
        if ($value != 1) {
            $segment .= 's';
        }
        $string[] = $segment;
    }
 
    return implode(', ', $string);
}

a flexible function for making time periods readable

res_328774/PHP Load Time ( PHP)

<?php
// code for TOP of the page
$start = microtime();
$startarray = explode(" ", $start);
$start = $startarray[1] + $startarray[0];
?>

<?php
// code for BOTTOM of the page
$end = microtime();
$endarray = explode(" ", $end);
$end = $endarray[1] + $endarray[0];
$total = $end - $start;
$total = round($total,2);
echo $total." seconds</a>";
?>

erraja_07/PHP - Display Updated time ( PHP)

function time_ago( $datefrom )
	{
	 	$dateto = date('Y-m-d H:i:s');
	 //  echo $dateto."-";
	//   echo $datefrom;
	  
	   if($datefrom<=0) { return "A long time ago"; }
	   if($dateto==-1) { $dateto = time(); }
	  
	   $difference = $dateto - $datefrom;
	  
	   // Seconds
	   if($difference < 60)
	   {
		 // $time_ago   = $difference . ' second' . ( $difference > 1 ? 's' : '' ).' ago';
	  $time_ago ='Just now';
	   }
	  
	   // Minutes
	   else if( $difference < 60*60 )
	   {
			$ago_seconds   = $difference % 60;
			$ago_seconds   = ( ( $ago_seconds AND $ago_seconds > 1 ) ? ' and '.$ago_seconds.' seconds' : ( $ago_seconds == 1 ? ' and '.$ago_seconds.' second' : '' ) );
			$ago_minutes   = floor( $difference / 60 );
			$ago_minutes   = $ago_minutes . ' minute' . ( $ago_minutes > 1 ? 's' : '' ).' ago';
			$time_ago      = $ago_minutes;
	   }
	  
	   // Hours
	   else if ( $difference < 60*60*24 )
	   {
			 $ago_minutes   = round( $difference / 60 ) % 60 ;
		   $ago_minutes   = ( ( $ago_minutes AND $ago_minutes > 1 ) ? ' and ' . $ago_minutes . ' minutes' : ( $ago_minutes == 1 ? ' and ' . $ago_minutes .' minute' : '' ));
		   $ago_hours      = floor( $difference / ( 60 * 60 ) );
		   $ago_hours      = $ago_hours . ' hour'. ( $ago_hours > 1 ? 's' : '' );
		   $time_ago      = $ago_hours.$ago_minutes.' ago';
	   }
	  
	   // Days
	   else if ( $difference < 60*60*24*7 )
	   {
		  $ago_hours      = round( $difference / 3600 ) % 24 ;
		  $ago_hours      = ( ( $ago_hours AND $ago_hours > 1 ) ? ' and ' . $ago_hours . ' hours' : ( $ago_hours == 1 ? ' and ' . $ago_hours . ' hour' : '' ));
		  $ago_days      = floor( $difference / ( 3600 * 24 ) );
		  $ago_days      = $ago_days . ' day' . ($ago_days > 1 ? 's' : '' );
		  $time_ago      = $ago_days.$ago_hours.' ago';
	   }
	  
	   // Weeks
	   else if ( $difference < 60*60*24*30 )
	   {
		  $ago_days      = round( $difference / ( 3600 * 24 ) ) % 7;
		  $ago_days      = ( ( $ago_days AND $ago_days > 1 ) ? ' and '.$ago_days.' days' : ( $ago_days == 1 ? ' and '.$ago_days.' day' : '' ));
		  $ago_weeks      = floor( $difference / ( 3600 * 24 * 7) );
		  $ago_weeks      = $ago_weeks . ' week'. ($ago_weeks > 1 ? 's' : '' );
		  $time_ago      = $ago_weeks.$ago_days.' ago';
	   }
	  
	   // Months
	   else if ( $difference < 60*60*24*365 )
	   {
		  $days_diff   = round( $difference / ( 60 * 60 * 24 ) );
		  $ago_days   = $days_diff %  30 ;
		  $ago_weeks   = round( $ago_days / 7 ) ;
		  $ago_weeks   = ( ( $ago_weeks AND $ago_weeks > 1 ) ? ' and '.$ago_weeks.' weeks' : ( $ago_weeks == 1 ? ' and '.$ago_weeks.' week' : '' ) );
		  $ago_months   = floor( $days_diff / 30 );
		  $ago_months   = $ago_months .' month'. ( $ago_months > 1 ? 's' : '' );
		  $time_ago   = $ago_months.$ago_weeks.' ago';
	   }
	  
	   // Years
	   else if ( $difference >= 60*60*24*365 )
	   {
		  $ago_months   = round( $difference / ( 60 * 60 * 24 * 30.5 ) ) % 12;
		  $ago_months   = ( ( $ago_months AND $ago_months > 1 ) ? ' and ' . $ago_months . ' months' : ( $ago_months == 1 ? ' and '.$ago_months.' month' : '' ) );
		  $ago_years   = floor( $difference / ( 60 * 60 * 24 * 365 ) );#30 * 12
		  $ago_years   = $ago_years . ' year'. ($ago_years > 1 ? 's' : '' ) ;
		  $time_ago   = $ago_years.$ago_months.' ago';
	   }
	  
	   return $time_ago;
	}

lafayette/PHP sort files by time ( PHP)

function sortByChangeTime($file1, $file2)
{
    return (filectime($file1) < filectime($file2)); 
}
$files = glob('*.*');              // use scandir if you want hidden files too
usort($files, 'sortByChangeTime'); // sort by callback
var_dump($files);                  // dump sorted file list

//ALTERNATIVE VERSION

if($h = opendir($dir)) {
  $files = array();
  while(($file = readdir($h) !== FALSE)
    $files[] = stat($file);

  // do the sort
  usort($files, 'your_sorting_function');

  // do something with the files
  foreach($files as $file) {
    echo htmlspecialchars($file);
  }
}