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

  • SEARCH
  • Home
  • 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 6010709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:09:20+00:00 2026-05-23T02:09:20+00:00

Im going to implement a search function in mySQL for an application Im building,

  • 0

Im going to implement a search function in mySQL for an application Im building,
the user types [for now, later will be a calendar picker] start date and end date,
and click search

  1. if (start day > end day), THEN error
  2. if (start month > end month), THEN error

Ok so far, but when having into account that

  1. if (start day > end day) && (start month < end month), THEN search
  2. if (start Month > end Month) && (start year < end year), THEN search

I dont worry about leap years, I will loop all months to 31 days, because if the day is in the db, it will fetch it, other wise, it will go to 31 and return nothing as there is no day,

Im using varchar for my dates (no timestamp), as they are imported from json [iOS]

Ok, hope to make sense,

here the code,

<?PHP
  $start = $_POST['start_date'];
  $end = $_POST['end_date'];
  $start_time = explode('/', $start);
  $end_time = explode('/', $end);
   $count_start = $start_time[0];
  $count_end = $end_time[0];
  $month_start = $start_time[1];
  $month_end = $end_time[1];
  $year_start = $start_time[2];
  $year_end = $end_time[2];

  function cuenta($count_start, $count_end) {

for($count_start; $count_start <= $count_end; $count_start++) {

    print $count_start . "<BR>";
}

     }

     if (!isset($_POST['Submit1']) || ($start == "Start Date" && $end == "End Date") || ($start == "" && $end == "End Date") || ($start == "Start Date" && $end == "")
|| ($start == "" && $end == "")) 

    {

print ("no data yet")."<BR>";
    }

    if ($year_start[2] > $year_end[2]){

print ("Please make sure end date Year is equal or greater than start date Year");
}

    if (($month_start > $month_end) && ($year_start <= $year_end)){

print ("Please make sure end date Month is greater than start date Month");

     }
     elseif (($month_start > $month_end) && ($year_start < $year_end)){

cuenta($count_start, $count_end);           
     }

    elseif ($count_start > $count_end) {
print ("Please make sure end date Day is greater than start date Day");

    }


    ?>

Im beggining in php, Sorry if I miss the obvious!, [that is why im asking haha]
so if im missing some other important validation for searching between a date range, plz let me know, and also plz point me in the best direction for this forest of ifs!

thanks a lot!

  • 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-05-23T02:09:20+00:00Added an answer on May 23, 2026 at 2:09 am

    Its much easier to convert the dates to unix timestamps and then compare the integers. PHP has the function strtotime for this purpose. If you have the dates already split, you could use mktime.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to implement fuzzy search for a small PHP/MySQL application. Specifically, I have
I am going to implement a function that will download a large file (about
I am trying to implement a search function on a database table using query
I am going to implement Lucene search into my project and I want to
I am going to implement the Calculator type application. In that I have set
I'm still trying to implement a search function into my Android app. So far
I'm going to implement license key generator on my website but I've very few
I'm going to implement my strings with internationalization in my Android app. I have
What's the best way going forward to implement Wake on LAN using C#? The
I've been tasked (coursework @ university) to implement a form of path-finding. Now, in-spec,

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.