Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
Forum date Response based on if statement matches 1 of 12 equal to or greater than comparisons (arguements)

Ok So I am working on a forum submit php code, lets call the file name index.html that takes forum date submitted in first below code.

<center>
  <form name="birthDay" method="post" action="months.php">
    <input type="date" id="birthDay" name="birthDay"><br>
    <input type="submit" name="Submit" value="send"><br>
  </form>
</center>

The php file months.php will take variable birthday and submit it to the months php file. as such.

<?php 
if(isset($_POST['birthDay'])) {
  $link = $_POST['birthDay']; //Month for Jan 
  $janBegin = date("01-01"); 
  $janEnd = date("01-31");  

  if ($birthDate >= $janBegin || $birthDate <= $janEnd) { 
    echo "Your birthday month is janurary"; 
  } 
?>

And so on based on all 12 months . When submitting forum.

My question is how do I create the list for the variable "birthday" to be compared to all months start and end date?

I have looked at if, elseif, swith-case statements but nothing is not creating desired results? I may be doing something wrong. But not able to pinpoint the error in my code.

That's what brings me here.

Any help on this is very much appreciated. Thanks

As Per Requested Via ADyson

This code is just an example of what I am trying to do. I have stated in comments below that start and end dates will be set at random variables. Total Variables set will be 12. This is why I choose to use beginning and end dates of the month. ADyson I believe took the idea a bit more literal Then I was hoping.

Basically Code will look like this.

<?php 
$startdate1 = date("01/20") 
$enddate1=date("02/27") 
if ($bday >= $startdate1 && $bday <= $enddate1) {
  echo "response #1";

I also have been researching more into this and found a snippet of code using if and elseif statements witch I found to work. But still come across an issue.

When date is entered and it loops through the code It matches a wrong response. so say a date of 08/27 (m-d) is entered it stops and matches

$option11Begin = date("11/25"); 
$option11End = date("12/23"); 

comparison

} elseif ($bday >= $option11Begin && $bday <= $option11End) {

any idea's why this is happening. Thanks.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You don't need to compare to start and end dates or have massive switch statements. Just feed the date into PHP's built-in DateTime class, which specialises in processing dates, and then output only the month name from the resulting object.

if(isset($_POST['birthDay'])) {
  $bday = new DateTime($_POST['birthDay']);
  echo "Your birthday month is ".$bday->format("F");
}

Simulation: http://sandbox.onlinephpfunctions.com/code/f4b8730927927adf976dfb103c58ba132ca9217f

Documentation link: https://www.php.net/manual/en/class.datetime.php

This solution will work for any day of the month. It parses the date string, and then from the resulting DateTime object you can always get the month value - or any other information you want, or do other comparisons to other DateTime objects, or whatever you need. This is much easier and more reliable than any kind of string comparisons

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!