dt3999 2017-03-14 14:40
浏览 17

查找带整数的随机时间

I am looking to generate a random number say 01:20 and then add 8 hours onto that and store that as a variable. However I want to do this within only the time and not use any random integers.

The date given for the query is found using a preset date at the moment set to 01-01-2017. StaffID is gotten from a loop through another table.

This is the PHP code snippet.

strtotime($random_hour = rand(00,23));
echo $random_hour . " Hour <br> ";
strtotime($random_min = rand(01,59));
echo $random_min . " Min <br> ";
$randomhourmin = $random_hour . ":" . $random_min;
echo $randomhourmin . "<br>";

This is the final SQL insert query.

$sql = "INSERT INTO schedule (staffID, cdate, starttime, endtime, dayoff) VALUES ('$rowID','$fDate','$randomhourmin','$randomhourmin','0')";
  • 写回答

1条回答 默认 最新

  • doulu8537 2017-03-14 14:43
    关注

    You can use below

    $int= rand(1262055681,1262055681);
    

    Also check mt_rand(), which is to have better randomness in the results:

    $int= mt_rand(1262055681,1262055681);
    

    To turn a timestamp into a string, you can use date(), ie:

    $string = date("Y-m-d H:i:s",$int);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?