<legend id='HMHhj'><style id='HMHhj'><dir id='HMHhj'><q id='HMHhj'></q></dir></style></legend>

        <i id='HMHhj'><tr id='HMHhj'><dt id='HMHhj'><q id='HMHhj'><span id='HMHhj'><b id='HMHhj'><form id='HMHhj'><ins id='HMHhj'></ins><ul id='HMHhj'></ul><sub id='HMHhj'></sub></form><legend id='HMHhj'></legend><bdo id='HMHhj'><pre id='HMHhj'><center id='HMHhj'></center></pre></bdo></b><th id='HMHhj'></th></span></q></dt></tr></i><div id='HMHhj'><tfoot id='HMHhj'></tfoot><dl id='HMHhj'><fieldset id='HMHhj'></fieldset></dl></div>
      1. <small id='HMHhj'></small><noframes id='HMHhj'>

        <tfoot id='HMHhj'></tfoot>

        • <bdo id='HMHhj'></bdo><ul id='HMHhj'></ul>

        如何在指定的日期范围内在 SQL 中更新/插入随机日期

        How to update/Insert random dates in SQL within a specified Date Range(如何在指定的日期范围内在 SQL 中更新/插入随机日期)
          <bdo id='NEGCs'></bdo><ul id='NEGCs'></ul>
          <i id='NEGCs'><tr id='NEGCs'><dt id='NEGCs'><q id='NEGCs'><span id='NEGCs'><b id='NEGCs'><form id='NEGCs'><ins id='NEGCs'></ins><ul id='NEGCs'></ul><sub id='NEGCs'></sub></form><legend id='NEGCs'></legend><bdo id='NEGCs'><pre id='NEGCs'><center id='NEGCs'></center></pre></bdo></b><th id='NEGCs'></th></span></q></dt></tr></i><div id='NEGCs'><tfoot id='NEGCs'></tfoot><dl id='NEGCs'><fieldset id='NEGCs'></fieldset></dl></div>
          • <small id='NEGCs'></small><noframes id='NEGCs'>

                  <legend id='NEGCs'><style id='NEGCs'><dir id='NEGCs'><q id='NEGCs'></q></dir></style></legend>

                    <tbody id='NEGCs'></tbody>
                1. <tfoot id='NEGCs'></tfoot>
                  本文介绍了如何在指定的日期范围内在 SQL 中更新/插入随机日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  请原谅我.我是一个绝对的新手,我需要帮助处理 phpmyadmin 中的这个表

                  Please forgive me. I am an absolute newbie and I need help with this table in phpmyadmin

                  我的表有以下列:

                  Primary_ID, Begin_Date, End_Date, Timestamp
                  

                  如何在 phpmyadmin 中更新选定的行,在指定的日期范围内(例如:一个月 30 天)随机生成 begin_dates 和时间戳.例如期望的结果

                  How do I update in phpmyadmin, selected rows with randomly generated begin_dates and timestamp within a specified date range (eg: 30 days in a month). E.g of desired outcome

                  Primary_id--- Begin_Date -------------Timestamp
                  
                  1.------------2008-09-02--------------2008-09-02 21:48:09
                  
                  2.------------2008-09-03--------------2008-09-03 15:19:01
                  
                  3.------------2008-09-14--------------2008-09-14 01:23:12
                  
                  4.------------2008-09-27--------------2008-09-27 19:03:59
                  

                  日期范围在 2008-09-01 和 2008-09-31 之间.时间 24 小时可变

                  Date Range between 2008-09-01 and 2008-09-31. Time is variable 24 hrs

                  我是新手,所以在 phpmyadmin 中可以使用的语法会有很大帮助.

                  I am a newbie, so a syntax that will work in phpmyadmin will help greatly.

                  我们正在为一个拥有 500 名会员的健身房网站制作演示文稿,但添加的会员值都具有相同的开始日期和时间.尝试将它们在数据库中分成不同的每月注册,例如8 月不同日期和时间注册的50 人,10 月35 人等.希望现在更清楚.谢谢——

                  We are making a presentation for a gym site with 500 members but the added member values all have the same begin date and time. Trying to separate them into different monthly registrations in the database, eg 50 people registered in August at different days and times, 35 people in October, etc. Hope it is clearer now. Thanks –

                  当我尝试以下答案之一时,出现此错误:#1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的$randomDate = rand(1,31)"附近使用的正确语法.因此,理想情况下,我可以将代码复制并粘贴到 phpmyadmin 中并进行最少的编辑,我将不胜感激.如果可能,按顺序排列.让一个完全的假人理解和执行.

                  When I try one of the below answers, I get this error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$randomDate = rand(1,31)' at line 1. So ideally, a code I can copy and paste into phpmyadmin with minimal editing will be appreciated. In sequence if possible. For a total dummy to understand and execute.

                  推荐答案

                  我会从这样的事情开始.可以将其中的一堆组合在一起,但我将其拆分以便您可以看到我在做什么.

                  I'd start with something like this. A bunch of these can be combined, but I split it up so you can see what I'm doing.

                  要获得随机数,您可以使用 rand().获取日期,小时,分钟和秒

                  To get random numbers, you can use rand(). Get one for the date, hour, minute, and second

                  $randomDate = rand(1,31);
                  $randomHour = rand(1,24);
                  $randomMinute = rand(0,59);
                  $randomSecond = rand(0,59);
                  

                  您需要前导零(03 而不是 3),以便您可以在需要时使用 str_pad 添加它们

                  You will want leading zeros (03 instead of 3) so you can use str_pad to add them, if required

                  $randomDate = str_pad($randomDate, 2, '0',STR_PAD_LEFT);
                  //The '2' is how many characters you want total
                  //The '0' is what will be added to the left if the value is short a character
                  

                  对所有其他随机值执行相同操作.正因为我喜欢简洁的查询,所以接下来你应该组成你的最终更新字符串.

                  Do the same with all your other random values. Just because I like neat queries, you should make up your final update strings next.

                  $newDate = '2008-09-'.$randomDate;
                  $newTime = $randomHour.':'.$randomMinute.':'.$randomSecond;
                  

                  现在我不知道您如何确定要更新哪些行,所以我将把它留给您.例如,如果您想使用 Primary_id 3 执行此操作,我将向您展示一个查询:

                  Now I don't know how you're determining which rows you want to update, so I will leave that up to you. For an example, I will show you a query if you wanted to do this with Primary_id 3:

                  $x = mysql_query("UPDATE yourTable SET Begin_Date="$newDate", Timestamp="$newTime" WHERE Primary_id = 3");
                  

                  这篇关于如何在指定的日期范围内在 SQL 中更新/插入随机日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Appending GET parameters to URL from lt;formgt; action(将 GET 参数附加到来自 lt;formgt; 的 URL行动)
                  Forcing quot;Save Asquot; dialog via jQuery GET(强制“另存为通过 jQuery GET 对话框)
                  PHP - get certain word from string(PHP - 从字符串中获取某个单词)
                  How to debug a get request in php using curl(如何使用 curl 在 php 中调试 get 请求)
                  get a # from a url in php(从 php 中的 url 获取 #)
                  PHP - include() file not working when variables are put in url?(PHP - 将变量放入 url 时,include() 文件不起作用?)
                  <tfoot id='0d0nS'></tfoot>
                      <bdo id='0d0nS'></bdo><ul id='0d0nS'></ul>
                      <i id='0d0nS'><tr id='0d0nS'><dt id='0d0nS'><q id='0d0nS'><span id='0d0nS'><b id='0d0nS'><form id='0d0nS'><ins id='0d0nS'></ins><ul id='0d0nS'></ul><sub id='0d0nS'></sub></form><legend id='0d0nS'></legend><bdo id='0d0nS'><pre id='0d0nS'><center id='0d0nS'></center></pre></bdo></b><th id='0d0nS'></th></span></q></dt></tr></i><div id='0d0nS'><tfoot id='0d0nS'></tfoot><dl id='0d0nS'><fieldset id='0d0nS'></fieldset></dl></div>
                        <legend id='0d0nS'><style id='0d0nS'><dir id='0d0nS'><q id='0d0nS'></q></dir></style></legend>

                            <tbody id='0d0nS'></tbody>

                            <small id='0d0nS'></small><noframes id='0d0nS'>