简体   繁体   中英

Add days and months on a date time with php

I want to make a textBox where you can enter a date time and then you choose a option in a dropdown menu. The dropdown menu has a calculation.

For example:

if ($exampleMonth === 11 && $exampleDay > 30) {
    $exampleMonth = 12;
    $exampleDay = 1; 
}

The dropdown menu is connected with my database:

require("require.php");

$oMy = new clsMYSQL();
$oMy->Query("select * IKE_EventTemplate where EventCode in ('H17', 'H18', 'H19', 'H20', 'H21')");
while(!$oMy->eof)
{
    echo  $oMy->row['EventCode'];;
    $hFvg = $oMy->row['EventCode'];

    if ($hFvg === 'H17' || $hFvg === 'H18' || $hFvg === 'H19' || $hFvg === 'H20' || $hFvg === 'H21') {
        //  hFdate = fs.event.eventDate;
        $year = ($hFdate.getFullYear());
        $month = ($hFdate.getMonth());
        $day = ($hFdate.getDate());

So I make you a example.

  1. You type in "12 October 2018" in the text Box.
  2. You choose a option in the dropdown menu called "Example1"
  3. You press button "Get solution"
  4. Text Box 2 shows the solution = 31. December 2021

在此处输入图片说明

don't exactly know what you are looking for but maybe this helps:

date_add($Date, date_interval_create_from_date_string('1 month'));//add 1 month of time to the variable $Date

you could also use date_sub() to subtract days

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM