Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It would be better if you store his TimeZone. People in different parts of the world have different time, so start of the day would be different for each one of them.</p> <p>You can get the current date and current time. Check how many posts have been made from the start of the day <code>00:00</code> on this particular day. If the number equals to 4, then tell the user that he has reached the maximum limit.</p> <p>Using <code>NOW()</code> you can use to get the current date and time</p> <pre><code>mysql&gt; SELECT NOW(); +---------------------+ | NOW() | +---------------------+ | 2009-10-22 10:49:15 | +---------------------+ 1 row in set (0.00 sec) </code></pre> <p>You must be knowing at what timezone your server is, then make the time UTC and add/subtract the time to get the Local time of the user.</p> <p>You would probably like to have a look at the <a href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html" rel="nofollow noreferrer">MySQL Data and time Reference</a></p> <ul> <li><a href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date" rel="nofollow noreferrer"><code>DATE()</code></a> - get the current date</li> <li><a href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_curtime" rel="nofollow noreferrer"><code>CURTIME()</code></a> - Get the current time</li> <li><a href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_convert-tz" rel="nofollow noreferrer"><code>CONVERT_TZ</code></a> - converting from one time zone to another</li> </ul> <p><strong>How to get the start of the day in Database</strong></p> <p>It should not be a problem, as I said, get the current time from DB, adjust your time difference to make the time UTC. then adjust the timezone of the user to make the time as per his timezone.</p> <p>e.g. <code>3:30</code>(server time) - <code>1:00</code>(server timezone) + <code>5:30</code>(User's timezone) = <code>8:00</code> (user's time)</p> <p>So, the start of the day for this user is 00:00 and it's 8 hrs elapsed for this user.</p> <p>N.B: Take care of the time difference. e.g. <code>2:30</code> - <code>3:30</code> = <code>-1:00</code> which means <code>23:00</code> on the previous day. Take this also in consideration.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload