www.webdeveloper.com
Results 1 to 6 of 6

Thread: Get row where epoch equals zero seconds

  1. #1
    Join Date
    Apr 2005
    Location
    Oregon
    Posts
    144

    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!
    Jeremy

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    22,335
    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).
    Code:
    . . . WHERE MOD(column_name, 15*60) = 0 . . .
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Apr 2005
    Location
    Oregon
    Posts
    144
    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());
    Thank you for any help you can provide.
    Jeremy

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    22,335
    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;")?
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  5. #5
    Join Date
    Apr 2005
    Location
    Oregon
    Posts
    144
    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
    Jeremy

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    22,335
    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?):
    PHP Code:
    <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>
    Output:
    Code:
    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)
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.14181 seconds
  • Memory Usage 2,915KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (4)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • bbcode_parse_start
  • postbit_imicons
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates