Jump to content

Recommended Posts

Well, you'll need to do a comparison then won't you? You'll need both times in the form of integers. So you'll have to use strtotime()/mktime() to convert your dates to unix timestamps.

 

If you're trying to do it in a mysql query, use the mysql UNIX_TIMESTAMP() function.

 

Perhaps if you explain your situation more fully, we'll be able to give you more help.

Link to comment
https://forums.phpfreaks.com/topic/116888-solved-time/#findComment-601105
Share on other sites

So an action never happened the previous day? If no, you can convert the HH:MM:SS format to a timestamp with strtotime(). The function assumes the provided time is today, so we won't need to supply todays date:

 

<?php
$saved_time = '12:00:00';
$time = strtotime($saved_time);
$diff = time() - $time;
echo "Action happened $diff seconds ago.";
?>

Link to comment
https://forums.phpfreaks.com/topic/116888-solved-time/#findComment-601114
Share on other sites

Well basically i have a forum, i want to make it so each person can post once every 30 seconds. I have the persons last post time saved into the db, i then want to compare both the current time and last post time to see if 30 seconds has passed yet. if not i want to say so and stop the post being made.

Link to comment
https://forums.phpfreaks.com/topic/116888-solved-time/#findComment-601115
Share on other sites

So an action never happened the previous day? If no, you can convert the HH:MM:SS format to a timestamp with strtotime(). The function assumes the provided time is today, so we won't need to supply todays date:

 

<?php
$saved_time = '12:00:00';
$time = strtotime($saved_time);
$diff = time() - $time;
echo "Action happened $diff seconds ago.";
?>

 

That has sorted it, thanks alot.

 

Topic solved :D

Link to comment
https://forums.phpfreaks.com/topic/116888-solved-time/#findComment-601120
Share on other sites

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.