Jump to content

Unix Timestamp Problem


gladiator83x

Recommended Posts

You can use MySQL's DATEDIFF function:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]DATEDIFF(expr1,expr2)

DATEDIFF() returns expr1 – expr2 expressed as a value in days from one date to the other. expr1 and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation. [/quote]

[a href=\"http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/dat...-functions.html[/a]

As for doing that with PHP, check the user notes here:
[a href=\"http://www.php.net/mktime\" target=\"_blank\"]http://www.php.net/mktime[/a]
Link to comment
https://forums.phpfreaks.com/topic/12237-unix-timestamp-problem/#findComment-46664
Share on other sites

[!--quoteo(post=384976:date=Jun 17 2006, 10:33 AM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 17 2006, 10:33 AM) [snapback]384976[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You can use MySQL's DATEDIFF function:
[a href=\"http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/dat...-functions.html[/a]

As for doing that with PHP, check the user notes here:
[a href=\"http://www.php.net/mktime\" target=\"_blank\"]http://www.php.net/mktime[/a]
[/quote]


I am having a problem using the DATEDIFF function. This is what I am typing in:

$diff= SELECT DATEDIFF($test_date,$creation_ts);
echo $diff;

This is the output that I receive:
SELECT DATEDIFF(2006-06-17 21:24:48,2004-08-09 11:01:24)

It doesn't subtract the dates. When I typed in the same thing minus the SELECT, it didnt recognize the DATEDIFF function.

$diff= DATEDIFF($test_date,$creation_ts);
echo $diff;


Anyone have any suggestions???
Link to comment
https://forums.phpfreaks.com/topic/12237-unix-timestamp-problem/#findComment-46875
Share on other sites

[!--quoteo(post=385208:date=Jun 17 2006, 09:33 PM:name=robos99)--][div class=\'quotetop\']QUOTE(robos99 @ Jun 17 2006, 09:33 PM) [snapback]385208[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Maybe I'm nitpicking here but isn't 2006-06-17 09:50:37 not a Unix timestamp? I may be wrong though.
[/quote]

I'm pretty sure that's a Unix timestamp, check the PHP documentation
Link to comment
https://forums.phpfreaks.com/topic/12237-unix-timestamp-problem/#findComment-46899
Share on other sites

[!--quoteo(post=385208:date=Jun 17 2006, 10:33 PM:name=robos99)--][div class=\'quotetop\']QUOTE(robos99 @ Jun 17 2006, 10:33 PM) [snapback]385208[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Maybe I'm nitpicking here but isn't 2006-06-17 09:50:37 not a Unix timestamp? I may be wrong though.
[/quote]


Hi Robos99,

I believe that it is definitely a Unix Timestamp. Check out the link:

[a href=\"http://en.wikipedia.org/wiki/Unix_epoch\" target=\"_blank\"]http://en.wikipedia.org/wiki/Unix_epoch[/a]

Link to comment
https://forums.phpfreaks.com/topic/12237-unix-timestamp-problem/#findComment-46900
Share on other sites

[!--quoteo(post=385217:date=Jun 17 2006, 10:49 PM:name=gladiator83x)--][div class=\'quotetop\']QUOTE(gladiator83x @ Jun 17 2006, 10:49 PM) [snapback]385217[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi Robos99,

I believe that it is definitely a Unix Timestamp. Check out the link:

[a href=\"http://en.wikipedia.org/wiki/Unix_epoch\" target=\"_blank\"]http://en.wikipedia.org/wiki/Unix_epoch[/a]
[/quote]


The code that Fyorl definitely looks correct, and I know that I am connecting to the database but I keep getting the following error:

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /export/home2/webpages/confirm.php on line 86

I changed it up a couple of times, and still nothing. Anybody else ever get this error message, and if so...what did you do to fix it?

Link to comment
https://forums.phpfreaks.com/topic/12237-unix-timestamp-problem/#findComment-46917
Share on other sites

You are not picking it up guys... Usually, a UNIX timestamp is an integer representing the seconds since the UNIX epoch.

1150552200 = 06/17/2006 - 09:50

Now, MySQL doesn't need a UNIX timestamp to calculate DATEDIFF.
You are going to need MySQL >= 4.1 to use it though.
Link to comment
https://forums.phpfreaks.com/topic/12237-unix-timestamp-problem/#findComment-46920
Share on other sites

[!--quoteo(post=385266:date=Jun 18 2006, 03:07 AM:name=jajtiii)--][div class=\'quotetop\']QUOTE(jajtiii @ Jun 18 2006, 03:07 AM) [snapback]385266[/snapback][/div][div class=\'quotemain\'][!--quotec--]
A Unix Timestamp is [b]always[/b] an integer. Month names, day names and the roman values of years have nothing to do with a Unix Timestamp.
[/quote]
Thanks for your remark jajtii. I didn't want to use a forceful word because my definition of "timestamp" leaves a gray area for interpretation, what I mean with "usually" is that 'Jun 18 2006, 03:07 AM' for example is a "Unix [compatible] timestamp" [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /]

If this is not correct, please tell me
Link to comment
https://forums.phpfreaks.com/topic/12237-unix-timestamp-problem/#findComment-46968
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.