Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8568807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:11:32+00:00 2026-06-11T18:11:32+00:00

Hello everyone: I am trying to get a data pull from MySQL within a

  • 0

Hello everyone: I am trying to get a data pull from MySQL within a PHP file that I have. The user passes in a date (represented currently by ‘$selectedDate’), and I want the query to pull all events that match that date.

The problem is that the MySQL date is in a unix format, meaning it has hours, seconds, etc. The passed in date is date only, so there won’t be an exact match.

So what I am trying to do is take my date, add a variable that is minus 1 day and another one that is plus one day and pull the events in based on that range.

The problem is that it’s not working and I have no idea why! After about 2 days of trouble shooting and searching, I am relying on you my stackoverflow friends!

Any ideas?

  $selectedDate = '9-20-2012';
  $dateComponents = preg_split('~[+*/-]~', $selectedDate);
  $date1 = mktime(0, 0, 0, ( (int)$dateComponents[0] ), (int)$dateComponents[1]-1, (int)$dateComponents[2]);
  $date2 = mktime(0, 0, 0, ( (int)$dateComponents[0] ), (int)$dateComponents[1]+1, (int)$dateComponents[2]);

  $query = "SELECT id,title,start, DATE_FORMAT(start, '%Y-%m-%d %H:%i' ) AS startDate, end, url, className FROM $tableName WHERE start BETWEEN '$date1' AND '$date2' ORDER BY start";

  $result = mysql_query($query) or die(mysql_error());
  $array = array();

  while($row = mysql_fetch_assoc($result)){
        echo($row);
       $array[] = $row; 

  }  

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:11:33+00:00Added an answer on June 11, 2026 at 6:11 pm

    You can add the Minutes and Seconds to your dates before passing them into SQL.

      $selectedDate = '9-20-2012';
      $dateComponents = preg_split('~[+*/-]~', $selectedDate);
      $date1 = mktime(0, 0, 0, ( (int)$dateComponents[0] ), (int)$dateComponents[1]-1, (int)$dateComponents[2]);
      $date2 = mktime(0, 0, 0, ( (int)$dateComponents[0] ), (int)$dateComponents[1]+1, (int)$dateComponents[2]);
    
      $date1 = date('Y-m-d h:i',$date1);
      $date2 = date('Y-m-d h:i',$date2);
    
      $query = "SELECT id,title,start, DATE_FORMAT(start, '%Y-%m-%d %H:%i' ) AS startDate, end, url, className FROM $tableName WHERE start BETWEEN '$date1' AND '$date2' ORDER BY start";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello everyone im trying to create this tweak that copies a file from one
Hello Everyone Iam trying to bulk insert data from .dat file(unloaded from sybase) in
Hello everyone I been trying get php uploader working but having a lot of
hello everyone I am trying to make a script that steps through a list
Hello everyone I'm trying to improve my Java skills by solving some problems from
Hello everyone i am trying to format the input number range with php number_format
Hello everyone I have a question that I will describe as good as I
Hello everyone I have a question... I'm trying to make my sms faker app,
Possible Duplicate: sending post data from Iphone Hello everyone, I'm a new member of
Hello everyone, I have been banging my head really hard trying to solve this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.