byteGator -
thanks for looking into it.
i used your example but still struggle with some issues.
here is how i use it:
in my templates function.php file i use this.
function osc_date_difference($dateinterval) {
if(!function_exists('get_string')){
function get_string($string, $start, $end) {
$start = preg_quote($start, '|');
$end = preg_quote($end, '|');
$matches = preg_match_all('|'.$start.'([^<]*)'.$end.'|i', $string, $output);
return $matches > 0
? $output[1]
: array();
}
$string = $dateinterval;
$startdate = get_string($string, 'From', 'to');
$enddate = get_string($string, 'to', '');
$start = (int) (strtotime($startdate[0])/86400);
$end = (int) (strtotime($enddate[0])/86400);
$interval = $end - $start;
echo 'Interval is '.$interval.' days';
}
}
in my item.php file i use this:
<?php
$trip_duration = 'From August 25, 2013 to August 28, 2013';
echo osc_date_difference($trip_duration);
?>
in my item.php file i use the function osc_date_difference($trip_duration); several times in order to display (the interval in days)
it works for the first occurrence, but using the same function in the same file a second or third time, just displays nothing.
e.g.
<h1> <?php echo osc_date_difference($trip_duration); ?> </h1> //displays 3 days, given the string 'From August 25, 2013 to August 28, 2013'
<h2> <?php echo osc_date_difference($trip_duration); ?> </h2> //displays nothing
<h1> and <h2> are used in the same file on the same page.
am sure i just messed up with the functions, but cant figure out what should be the right way.
in simple. i have a string (From August 25, 2013 to August 28, 2013) which i need to extract the start and the end date, calculate the difference in days, and display it several times on my page.
i also thought maybe to get the date values direct from the datebase instate of extracting it out from the string, but i dont know how to get the values from the database. thats why i use the approach with extracting from the string.
hope i made it not to difficult to explain.
any idea or advice on how to achieve this?
thanks for helping
cheers