How to echo all dates between two dates?
for example:
From the date of 2020/07/29 to the date of 2020/08/02
I want to print the results
2020/07/29
2020/07/30
2020/07/31
2020/08/01
2020/08/02
The following code prints only to 2020/07/31
if(isset($_POST['submit'])){
$from_date= $_POST['from_date'];
$to_date = $_POST['to_date'];
for($from_date = $from_date ; strtotime("+$from_date Day") <= $to_date; $from_date++){
echo $from_date . "<br>";
}
}
Result:
2020/07/29
2020/07/30
2020/07/31
HTML FORM
<form action="" method="post">
<input type="date" name="from_date">
<input type="date" name="to_date" >
<input name="submit" type="submit" value="submit">
</form>
Thanks
Related
I want to insert data into table when selected date is Current Date or Yesterday's Date.
html code:
<input type="text" id="datepicker1" name="reportdate" class="gui-input" placeholder="Select Date" required="Select date" value="<?php echo date('d/m/Y'); ?>">
php code:
if(isset($_POST['submit'])){
$report_date=date('Y-m-d',strtotime($_POST['reportdate']));
$check_date=date('d',strtotime($_POST['reportdate']));
if($check_date!=date('d') or $check_date!=date('d')-1){
echo "<h2>You can only submit dcr of current date or yesterday.</h2>";
}
else{
$client=$_POST['CLIENT_NAME'];
//$cars_string = implode(', ', $_POST['cars']);
$productname_string=implode(', ',$_POST['productname']);
$remarks=$_POST['remark'];
$sql="insert into d_c_r (bm,date_time,client,promoted_product,remark) values ('".$_SESSION['id']."','$report_date',$client,'$productname_string','$remarks')";
$res=mysql_query($sql) or die(mysql_error());
}
}
Working Code Updated:
Working Demo: http://phpfiddle.org/main/code/fxh8-gnkw
<html>
<body>
<form action="" method="post" name="myform">
<input type="date" id="datepicker1" name="reportdate" class="gui-input" placeholder="Select Date" required="Select date" value="">
<button type="submit" name="submit"> Submit</button>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']) && !empty($_POST['reportdate'])){
$today_date = date('d-m-Y'); // you get current date
$date_tday = new DateTime($today_date);
$date_tday->modify('-1 day');
$get_yesterday_date_from_current = $date_tday->format('d-m-Y'); // you get Yesterday date that from current date
$reportdate = $_POST['reportdate']; // you get report date that user is selected
$report_date_format = new DateTime($reportdate);
echo $report_date = $report_date_format->format('d-m-Y'); //you get report date that user is selected in d-m-Y
/*
$date = new DateTime($report_date);
$date->modify('-1 day');
echo $get_yesterday_date = $date->format('d-m-Y'); // you get Yesterday date that user is selected
*/
if($report_date !== $today_date && $report_date !== $get_yesterday_date_from_current){
echo "<h2>You can only submit dcr of current Date or Yesterday.</h2>";
}
else{
echo "Inser Your Data OR What You WAnt To Do HERE";
}
}
?>
Im trying to create a timer that for 1 hour from a timestamp it shows a count down then after that shows a form button but I can't get it to work, I have tried multiple methods I found online but they either display the wrong time, or never show the form. Here is what I have so far:
while($row2 = $result2->fetch_assoc()) {
$timestamp = $row2['timestamp'];
$work_id = $row2['work_id'];
$current_time = date("Y-m-d H:i:s");
$ready_time = date("Y-m-d H:i:s", strtotime($timestamp)+3600);
if($current_time > $ready_time){?>
<form action="" method="POST" onsubmit="return confirm('Are you sure?');">
<input type="hidden" value="<?echo $work_id;?>" name="work_id">
<input type="submit" name="submit" value="Complete Workorder">
</form>
?
}else{
$time1 = new DateTime($current_time);
$time2 = new DateTime($timestamp);
$interval = $time1->diff($time2);
echo $interval->d ." Days ". $interval->h . " Hours, " . $interval->i." Mintues, ".$interval->s." seconds";
}
}
You can calculate the time left in your sql:
SELECT work_id, TIMESTAMPDIFF(SECOND,CURRENT_TIMESTAMP(),`timestamp`) AS timeleft
FROM tablename
Then check that value in your php:
$timeleft = $row2['timeleft'];
$work_id = $row2['work_id'];
if($timeleft >=0): ?>
<form action="" method="POST" onsubmit="return confirm('Are you sure?');">
<input type="hidden" value="<?echo $work_id;?>" name="work_id">
<input type="submit" name="submit" value="Complete Workorder">
</form>
<?php else: ?>
<p>You need to wait <?php echo $timeleft;?> seconds</p>
<?php endif;
If you want to chow a countdown that actually updates without a refresh, you will need to use javascript, in place of <p>You need to wait <?php echo $timeleft;?> seconds</p>
I'm trying to retrieve a date from a date input form and I just can't get it to work properly. The code I'm using now only returns an error and this date: 1970-01-01. That is not correct and I would like to know how I can approach this. This will be used later to query a database table. I want the date to be basically just a string with this format: "yyyy-mm-dd"
Code:
HTML
<form name="DateFilter" method="POST">
From:
<input type="date" name="dateFrom" value="<?php echo date('Y-m-d'); ?>" />
<br/>
To:
<input type="date" name="dateTo" value="<?php echo date('Y-m-d'); ?>" />
</form>
PHP
$new_date = date('Y-m-d', strtotime($_POST['dateFrom']));
echo $new_date;
~~~ EDIT ~~~
Fixed Solution for anyone wondering how it's done:
HTML
<form name="Filter" method="POST">
From:
<input type="date" name="dateFrom" value="<?php echo date('Y-m-d'); ?>" />
<br/>
To:
<input type="date" name="dateTo" value="<?php echo date('Y-m-d'); ?>" />
<input type="submit" name="submit" value="Login"/>
</form>
PHP
$new_date = date('Y-m-d', strtotime($_POST['dateFrom']));
echo $new_date;
Validate the INPUT.
$time = strtotime($_POST['dateFrom']);
if ($time) {
$new_date = date('Y-m-d', $time);
echo $new_date;
} else {
echo 'Invalid Date: ' . $_POST['dateFrom'];
// fix it.
}
<?php
if (isset($_POST['birthdate'])) {
$timestamp = strtotime($_POST['birthdate']);
$date=date('d',$timestamp);
$month=date('m',$timestamp);
$year=date('Y',$timestamp);
}
?>
I want to get the date in mysql using input type="date" .. please help for the code...
here is my code:
<form action="sales.php" method="get">
<input type="date" name="d1" value="" required="required" />
<input id="btn" type="submit" value="Search">
</form>
Here is my connection:
<?php
if (isset($_GET[ "d1"])) {
$do=$_GET[ "d1"];
} else {
$do=0;
};
$result=$ db->prepare("SELECT * FROM sales WHERE date=:a");
$result->bindParam(':a', $do);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
Thanks in advance
Inside that sales.php script print out:
$date_value = $_GET['d1'];
echo $date_value;
$myslq_date = date ('Y-m-d H:i:s', strtotime ($date_value));
But check for browser compatibility for that input type - not sure how it's supported.
I've started learning PHP, and just can't figure out how to accomplish this.
The basic question is to how to calculate age from current year..
I have to do it with a submit button, and that's the problem for me. I tried this:
<form name="form2" action="16.1.php" method="POST">
Birthday year:
<input type="post" name="post">
<input type="submit" value= "Verstuur" >
</form>
16.1php:
<?php
echo date ('Y') - $_POST['post'];
?>
Try updating this..
<input type="input" name="post">
type = "post" to type = "input"
Try this
if($_POST['submit'])
{
$byear = $_POST['bdate'];
$today = new DateTime();
$birthdate = new DateTime($byear);
$interval = $today->diff($birthdate);
echo $interval->format('%y years');
}
<form name="form2" action="" method="POST">
Birthday year:
<input type="text" name="bdate">(yyy-mm-dd)
<input type="submit" name="submit" value= "Verstuur" >
</form>