[PHP] Date comparison Question

2008-04-07 Thread admin
I am having a date time comparison issue. 
I have statically set the values here. But the data is fed from the database, 
CaldTime is timestamp and since it will not allow me to have 2 timestamps in 
the same table I set the CallEnd varchar(12). Storing the data they seem to be 
the same for output. I checked hexadecimal and binary to look for obscurities.


$sqldata['CaldTime']  = 2008-04-07 11:15:32;
$sqldata['CallEnd'] = 2008-04-07 11:17:17;

$time1 = strtotime($sqldata[CaldTime]);
$time2 = strtotime($sqldata[CallEnd]);
$interval = $time2 - $time1;

echo $interval;

+++
Displays like 1.75:0
I am looking for a more precise time like 1:45 instead.
Am I looking at this all wrong for time difference?

Richard L. Buskirk
Sorry my murloc got pawned in AV, and ever since I cant think right!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date comparison Question

2008-04-07 Thread Nathan Nobbe
On Mon, Apr 7, 2008 at 9:42 AM, [EMAIL PROTECTED] wrote:

 I am having a date time comparison issue.
 I have statically set the values here. But the data is fed from the
 database, CaldTime is timestamp and since it will not allow me to have 2
 timestamps in the same table I set the CallEnd varchar(12). Storing the data
 they seem to be the same for output. I checked hexadecimal and binary to
 look for obscurities.


 $sqldata['CaldTime']  = 2008-04-07 11:15:32;
 $sqldata['CallEnd'] = 2008-04-07 11:17:17;

 $time1 = strtotime($sqldata[CaldTime]);
 $time2 = strtotime($sqldata[CallEnd]);
 $interval = $time2 - $time1;

 echo $interval;

 +++
 Displays like 1.75:0
 I am looking for a more precise time like 1:45 instead.
 Am I looking at this all wrong for time difference?


hmm.
different results for me w/ this code

?php
$time1 = strtotime('2008-04-07 11:15:32');
$time2 = strtotime('2008-04-07 11:17:17');

echo time1: $time1 . PHP_EOL;
echo time2: $time2 . PHP_EOL;

$interval =  $time2 - $time1;
echo $interval . PHP_EOL;
?

time1: 1207588532
time2: 1207588637
105

-nathan


Re: [PHP] Date comparison Question

2008-04-07 Thread Mark J. Reed
On Mon, Apr 7, 2008 at 11:42 AM,  [EMAIL PROTECTED] wrote:
t the data is fed from the database, CaldTime is timestamp and since
it will not allow me to have 2 timestamps in
 the same table

?? What database are you using?  It sounds like it has a specific
meaning of timestamp - probably the last time this row was
modified - and you want an arbitrary date column, which would
probably be a different column type.  Not a string, though.  An actual
date type.  possible names are date, datetime, datestamp...


, and you  I set the CallEnd varchar(12). Storing the data they seem
to be the same for output. I checked hexadecimal and binary to look
for obscurities.


  $sqldata['CaldTime']  = 2008-04-07 11:15:32;
  $sqldata['CallEnd'] = 2008-04-07 11:17:17;

  $time1 = strtotime($sqldata[CaldTime]);
  $time2 = strtotime($sqldata[CallEnd]);
  $interval = $time2 - $time1;

  echo $interval;

  +++
  Displays like 1.75:0
  I am looking for a more precise time like 1:45 instead.
  Am I looking at this all wrong for time difference?

strtotime returns an integer number of seconds.  The difference
between $time1 and $time2 is 105.  If you want minutes and seconds,
you have to do the math yourself.

$interval_min = floor($interval/60);
$interval_sec = $interval % 60;

echo $interval_min:$interval_sec;

-- 
Mark J. Reed [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date comparison Question

2008-04-07 Thread admin
Yes my mistake was looking at another record and published another.
But I figured it out now i can publish 1:45 like i wanted. Having a moment 
there.
Thank you 
Richard L. Buskirk 




 
On Mon, Apr 7, 2008 at 9:42 AM, [EMAIL PROTECTED] wrote:

I am having a date time comparison issue.
I have statically set the values here. But the data is fed from the database, 
CaldTime is timestamp and since it will not allow me to have 2 timestamps in 
the same table I set the CallEnd varchar(12). Storing the data they seem to be 
the same for output. I checked hexadecimal and binary to look for obscurities.


$sqldata['CaldTime']  = 2008-04-07 11:15:32;
$sqldata['CallEnd'] = 2008-04-07 11:17:17;

$time1 = strtotime($sqldata[CaldTime]);
$time2 = strtotime($sqldata[CallEnd]);
$interval = $time2 - $time1;

echo $interval;

+++
Displays like 1.75:0
I am looking for a more precise time like 1:45 instead.
Am I looking at this all wrong for time difference?

hmm.
different results for me w/ this code

?php
$time1 = strtotime('2008-04-07 11:15:32');
$time2 = strtotime('2008-04-07 11:17:17');

echo time1: $time1 . PHP_EOL;
echo time2: $time2 . PHP_EOL;

$interval =  $time2 - $time1;
echo $interval . PHP_EOL;
?

time1: 1207588532
time2: 1207588637
105
 -nathan

Re: [PHP] Date comparison Question

2008-04-07 Thread admin
Thank you that is exactly what i did to figure it out.
Just was having a brain fart there for a minute.



On Mon, Apr 7, 2008 at 11:42 AM,  [EMAIL PROTECTED] wrote:
t the data is fed from the database, CaldTime is timestamp and since
it will not allow me to have 2 timestamps in
 the same table

?? What database are you using?  It sounds like it has a specific
meaning of timestamp - probably the last time this row was
modified - and you want an arbitrary date column, which would
probably be a different column type.  Not a string, though.  An actual
date type.  possible names are date, datetime, datestamp...


, and you  I set the CallEnd varchar(12). Storing the data they seem
to be the same for output. I checked hexadecimal and binary to look
for obscurities.


  $sqldata['CaldTime']  = 2008-04-07 11:15:32;
  $sqldata['CallEnd'] = 2008-04-07 11:17:17;

  $time1 = strtotime($sqldata[CaldTime]);
  $time2 = strtotime($sqldata[CallEnd]);
  $interval = $time2 - $time1;

  echo $interval;

  +++
  Displays like 1.75:0
  I am looking for a more precise time like 1:45 instead.
  Am I looking at this all wrong for time difference?

strtotime returns an integer number of seconds.  The difference
between $time1 and $time2 is 105.  If you want minutes and seconds,
you have to do the math yourself.

$interval_min = floor($interval/60);
$interval_sec = $interval % 60;

echo $interval_min:$interval_sec;

-- 
Mark J. Reed [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date comparison Question

2008-04-07 Thread Daniel Brown
On Mon, Apr 7, 2008 at 11:42 AM,  [EMAIL PROTECTED] wrote:
 I am having a date time comparison issue.
  I have statically set the values here. But the data is fed from the 
 database, CaldTime is timestamp and since it will not allow me to have 2 
 timestamps in the same table I set the CallEnd varchar(12). Storing the data 
 they seem to be the same for output. I checked hexadecimal and binary to look 
 for obscurities.


  $sqldata['CaldTime']  = 2008-04-07 11:15:32;
  $sqldata['CallEnd'] = 2008-04-07 11:17:17;

  $time1 = strtotime($sqldata[CaldTime]);
  $time2 = strtotime($sqldata[CallEnd]);
  $interval = $time2 - $time1;

  echo $interval;

  +++
  Displays like 1.75:0
  I am looking for a more precise time like 1:45 instead.
  Am I looking at this all wrong for time difference?

  Richard L. Buskirk
  Sorry my murloc got pawned in AV, and ever since I cant think right!

  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php



This could be simplified to a function, but using some basic math

?php
$sqldata['CaldTime'] = 2008-04-07 11:15:32;
$sqldata['CallEnd'] = 2008-04-07 11:17:17;

$converted = explode('.',((strtotime($sqldata['CallEnd']) -
strtotime($sqldata['CaldTime'])) / 60));
$converted[1] = (($converted[1] / 6) * 3.6);
echo implode(':',$converted).\n;

?


-- 
/Daniel P. Brown
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date comparison Question

2008-04-07 Thread admin
Dan I made a solution as below.

$time1 = strtotime($sqldata[CaldTime]);
$time2 = strtotime($sqldata[CallEnd]);
$interval = $time2 - $time1;
$TLength = date(i:s, strtotime(2008-01-01 01:00:$interval));

Result 01:45

Works perfect for me. Do you agree or disagree dan?




On Mon, Apr 7, 2008 at 11:42 AM,  [EMAIL PROTECTED] wrote:
 I am having a date time comparison issue.
  I have statically set the values here. But the data is fed from the 
database, CaldTime is timestamp and since it will not allow me to have 2 
timestamps in the same table I set the CallEnd varchar(12). Storing the data 
they seem to be the same for output. I checked hexadecimal and binary to look 
for obscurities.


  $sqldata['CaldTime']  = 2008-04-07 11:15:32;
  $sqldata['CallEnd'] = 2008-04-07 11:17:17;

  $time1 = strtotime($sqldata[CaldTime]);
  $time2 = strtotime($sqldata[CallEnd]);
  $interval = $time2 - $time1;

  echo $interval;

  +++
  Displays like 1.75:0
  I am looking for a more precise time like 1:45 instead.
  Am I looking at this all wrong for time difference?

  Richard L. Buskirk
  Sorry my murloc got pawned in AV, and ever since I cant think right!

  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php



This could be simplified to a function, but using some basic math

?php
$sqldata['CaldTime'] = 2008-04-07 11:15:32;
$sqldata['CallEnd'] = 2008-04-07 11:17:17;

$converted = explode('.',((strtotime($sqldata['CallEnd']) -
strtotime($sqldata['CaldTime'])) / 60));
$converted[1] = (($converted[1] / 6) * 3.6);
echo implode(':',$converted).\n;

?


-- 
/Daniel P. Brown
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date comparison Question

2008-04-07 Thread Daniel Brown
On Mon, Apr 7, 2008 at 1:03 PM,  [EMAIL PROTECTED] wrote:
 Dan I made a solution as below.


  $time1 = strtotime($sqldata[CaldTime]);
  $time2 = strtotime($sqldata[CallEnd]);
  $interval = $time2 - $time1;
  $TLength = date(i:s, strtotime(2008-01-01 01:00:$interval));

  Result 01:45

  Works perfect for me. Do you agree or disagree dan?

There ya' go!

-- 
/Daniel P. Brown
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Date Comparison Question

2001-01-26 Thread Martin Fernandez

I'm fairly new to php and still learning it's nuances, etc.

I've created a site - http://www.more-mtb.org - in which I have used several
php resources from around the net and some which I have created my self. On
the home page of the site I have inserted some code that displays a series
of events from a calendar table in a Mysql dB.

My idea is to display the 4 upcoming events from today (the current date)
including any events that match today's date.

The display works great until I get to the end of the month (like now). I
have separated the date as three rows in my dB (msg_year, msg_month and
msg_day)

when I do the query in my code to select the 4 upcoming events I use the
following:

$query = sprintf("SELECT * FROM calendar_messages WHERE msg_active=1 AND
msg_year = $ThisYear AND msg_month = $ThisMonth AND msg_day = $ThisDay
ORDER BY msg_year, msg_month, msg_day ASC LIMIT 0, 4 ");

The problem is, that even though the first three comparisons are met, the
last one , the msg_day is not. At the end of the month the day value is in
the high 20s/30s whereas the day value for the next month is in the low
digits. And even though my query satisfies the first two (three if you count
msg_active) comparisons the fourth is not satisfied and therefore the event
is skipped.

As soon as the next month starts, then I get 4 events.

I know exactly what's wrong, But my non-programmer limitations are coming to
light and I have absolutely no clue what to do next or how to proceed. Any
direction will be extremely appreciated.

Thanks in advance.

Martin


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]