douhuo3696 2012-04-04 20:42
浏览 28
已采纳

从时间戳计算

Yesterday I asked another question to calculate time.

Now I realized, that it makes no sense to use a second table for my project because everything that is necessary is already given in my first table. So, for the moment I use two tables where I insert two timestamps:

$time = "INSERT INTO table2 ( a, b, c) VALUES (NOW(),NOW() + INTERVAL 14 DAY,(unix_timestamp(NOW()+ INTERVAL 14 DAY)) - unix_timestamp(NOW()))";

Like I already said, it could be much easier and the same result will be reached without a second table. Now my problem is, this is the first time I have worked with timefunctions in php. There are a lot of different functions that I do not really understand.

I think to solve my problem I can use something like:

$row = fetch_assoc()
$old_timestamp = $row->b;

$actual_time = mktime(); //which makes an actual timestamp
$seconds = '1209600'; //which is exactly the timeperiod of 14 days
$added = $old_timestamp + $seconds; //which adds the seconds to the old timestamp and should be the same as NOW() + INTERVAL 14 DAY from the VALUE of the query
$date_to_check = $added - $actual_time;
   if $date_to_check <= 0 { 
     do something }

Is this possible? I would really appreciate if there is someone who can help. thanks a lot.

UPDATE

For everyone who likes to know what i have in mind. Here is the code for the actual way:

$time_check = $db->query("SELECT (B <= NOW()) AS var FROM table2 WHERE x='$x'");         
            while ($row = $time_check->fetch_object()){ 
                if (($row->var != 0) && ($var1 === '0')){
                        $update_status = $db->query("UPDATE table1 SET var1='1' WHERE x='$x'");{
                            $delete_timecount = $db->query("DELETE FROM table2 WHERE x='$x'");
                        }
                }
            }

I would like to accomplish the same result without a second table.

  • 写回答

1条回答 默认 最新

  • du67560 2012-04-04 21:06
    关注

    I can't really understand what you are trying to do. It appears that you are trying to recognize when 14 days have elapsed after someone's registration in order to do something.

    if (time() > $old_timestamp + 1209600) {
        // It's been 14 days
        // Do something
    }
    

    I used time, which simply returns the current time. Do you understand what a timestamp is?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景