/    Sign up×
Community /Pin to ProfileBookmark

Get row where epoch equals zero seconds

Hi, I would like to know if there is a way to get row results where the stored epoch time is matched to the quarter hour and zero seconds. Like this:

12:00:00
12:15:00
12:30:00
12:45:00
01:00:00
01:15:00
01:30:00
01:45:00

And any results that are like this:

12:00:02
12:25:00

Would be skipped. Thank you!

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 03.2013 — If you're storing it as an integer, then I suppose you could use modulus (MOD() function in MySQL), although any such solution will require a full table scan (indexes won't help).
<i>
</i>. . . WHERE MOD(column_name, 15*60) = 0 . . .
Copy linkTweet thisAlerts:
@towerboyauthorJul 06.2013 — Thank you for the reply. I played around with that but all that does is return a single record from a week ago. It is at 6:30 PM, but the table is full of more than just that record that meets my requirements. I tried playing with the math and got different results that make no logical sense to me. I also looked up the MOD function for MySQL and didn't understand enough of the examples to make any headway. I thought it may help if I posted my query line.
[CODE]$result = mysql_query("SELECT * FROM $siteID WHERE MOD(epoch, 15*60) = 0 ORDER by epoch DESC LIMIT $recordLimit") or die(mysql_error());[/CODE]
Thank you for any help you can provide.
Copy linkTweet thisAlerts:
@NogDogJul 08.2013 — Just to make sure we're on the same page, what is the actual type for the epoch field, and maybe include some sample raw data (e.g.: "SELECT epoch FROM table_name LIMIT 20;")?
Copy linkTweet thisAlerts:
@towerboyauthorJul 08.2013 — The field type is "int" and this is the raw data from 20 rows:
[CODE]1373261982
1373261401
1373261180
1373260729
1373260501
1373259601
1373258963
1373258701
1373258477
1373258269
1373257801
1373257703
1373257520
1373256901
1373256750
1373256364
1373256002
1373255741
1373255360
1373255102[/CODE]
Copy linkTweet thisAlerts:
@NogDogJul 08.2013 — As far as I can see, that should work. It so happens that the sample data you output does not contain any times that have a '00' for the seconds part, so none of those would match (unless you want to ignore the seconds and only look at the minutes part?):
[code=php]
<pre>
<?php

$testData = array(
1373261982,
1373261401,
1373261180,
1373260729,
1373260501,
1373259601,
1373258963,
1373258701,
1373258477,
1373258269,
1373257801,
1373257703,
1373257520,
1373256901,
1373256750,
1373256364,
1373256002,
1373255741,
1373255360,
1373255102,
);

foreach($testData as $test) {
printf(
"Remainder of %d %% (15*60) = % 3d (date: %s)".PHP_EOL,
$test,
$test % (15 * 60),
date('Y-m-d H:i:s', $test)
);
}
?>
</pre>[/code]

Output:
<i>
</i>Remainder of 1373261982 % (15*60) = 582 (date: 2013-07-08 01:39:42)
Remainder of 1373261401 % (15*60) = 1 (date: 2013-07-08 01:30:01)
Remainder of 1373261180 % (15*60) = 680 (date: 2013-07-08 01:26:20)
Remainder of 1373260729 % (15*60) = 229 (date: 2013-07-08 01:18:49)
Remainder of 1373260501 % (15*60) = 1 (date: 2013-07-08 01:15:01)
Remainder of 1373259601 % (15*60) = 1 (date: 2013-07-08 01:00:01)
Remainder of 1373258963 % (15*60) = 263 (date: 2013-07-08 00:49:23)
Remainder of 1373258701 % (15*60) = 1 (date: 2013-07-08 00:45:01)
Remainder of 1373258477 % (15*60) = 677 (date: 2013-07-08 00:41:17)
Remainder of 1373258269 % (15*60) = 469 (date: 2013-07-08 00:37:49)
Remainder of 1373257801 % (15*60) = 1 (date: 2013-07-08 00:30:01)
Remainder of 1373257703 % (15*60) = 803 (date: 2013-07-08 00:28:23)
Remainder of 1373257520 % (15*60) = 620 (date: 2013-07-08 00:25:20)
Remainder of 1373256901 % (15*60) = 1 (date: 2013-07-08 00:15:01)
Remainder of 1373256750 % (15*60) = 750 (date: 2013-07-08 00:12:30)
Remainder of 1373256364 % (15*60) = 364 (date: 2013-07-08 00:06:04)
Remainder of 1373256002 % (15*60) = 2 (date: 2013-07-08 00:00:02)
Remainder of 1373255741 % (15*60) = 641 (date: 2013-07-07 23:55:41)
Remainder of 1373255360 % (15*60) = 260 (date: 2013-07-07 23:49:20)
Remainder of 1373255102 % (15*60) = 2 (date: 2013-07-07 23:45:02)
×

Success!

Help @towerboy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...