Jump to content

Recommended Posts

[code]
2004-10-20 15:33:12
0123456789012345678[/code]

[code=php:0]<?php
$a = substr($date1, 5, 2); //days (or is it months? i suck with date formats) of date 1
$b = substr($date2, 5, 2); //days (months?) of date 2
?>[/code]

FYI: The key in the code block shows you the 'number' of charicters. '10-20' starts at offset 5, and has a length of 5.

Also, the 'type' of $a and $b is [u]String[/u], [b]not[/b] [u]Integer[/u].
look up strtotime

link
http://uk.php.net/strtotime

example only but check ok

put the dates in a friendly format selecting day.

$date1=strtotime("d",$what_ever_date_form_database);
$date2=strtotime("d",$what_ever_date_from_database);

$date_result=$date1-$date2;

echo $date_result;

not sure somethink like that.
My output doesnt return an error, so thats good. It just doesn't return anything. I tried the strtotime() function as well as the substr() function. Any idea what I am doing wrong? $col_val and $creation time return the time when I echo them out--It just seems like I cannot convert them into another form.


$date1=strtotime("d-m-y",$col_val);
$date2=strtotime("d-m-y",$creation_ts);

echo $date1;
$date_result=$date1-$date2;

echo $date_result;
The strtotime() function returns the number of seconds since 1-1-1970.

try:
[code]<?php
$date1=strtotime($col_val);
$date2=strtotime($creation_ts);

echo $date1;
$date_result=$date1-$date2;

echo $date_result;
$num_days = floor($date_result/86400); // 86400 is the number of seconds in a day
echo "<br>Days: $num_days";
?>[/code]

Ken
How did you figure those numbers? The first two are fine, the last two are completely wrong.

[code]<?php
$secs['secs_in_min'] = 60;
$secs['secs_in_hour'] = 60 * $secs['secs_in_min'];
$secs['secs_in_12hour'] = $secs['secs_in_hour'] * 12;
$secs['secs_in_day'] = $secs['secs_in_hour'] * 24;
echo '<pre>' . print_r($secs,true) . '</pre>';
?>[/code]

Ken
soory ken mate


Okay, here we go!  There are 60 seconds in a minute, and 60 minutes
in an hour.  So there are 60 x 60 seconds in an hour, in other words
3600 seconds in an hour.  Furthermore, there are 24 hours in a day,
so there are 24 x 3600 seconds = 86400 seconds in a day.  Also, there
are 365 days in a year, so there are 365 x 86400 seconds = 31,536,000
seconds in a year.  Let's summarize this in a table:

1 hour = 3600 seconds
1 day  = 86400 seconds
1 year = 31,536,000 seconds

$sixty_secons_to_min=60;

$one_hour_secons=3600;

$twelve_hours_secons=43200;

$twenty_four_hours_secons=86400;


This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.