How To Add +6 Months in current date [duplicate] - php

This question already has answers here:
Add six months in php
(5 answers)
Closed 6 years ago.
i want to add 6 months in current date. i have used the following date format.
$current_time = date('Y-m-d');
i have proceed with this method shown below but an error is occured.
'A non well formed numeric value encountered'.
and print this value
[expiring_plan_date] => 1970-01-02
$data['PlanPayment']['expiring_plan_date'] = date
(
"Y-m-d",
strtotime("+6 month", $current_time)
);
please help..

Remove comma from strtotime
$data['PlanPayment']['expiring_plan_date'] = date("Y-m-d", strtotime("+6 month $current_time));

Related

formatting date in php returning current year [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
PHP strtotime returning wrong results
(3 answers)
Closed 5 years ago.
I'm formatting date in php. But it's returning current year.
This is my code:
<?php
$date = "2 January, 2018";
echo date('d-m-Y', strtotime( $date ));
?>
I need date format in d-m-Y format.
Remove Comma
<?php
$date = "2 January 2018";
echo date('d-m-Y', strtotime( $date ));
?>
Remove the comma from the date string.

How to substract number of days in PHP [duplicate]

This question already has answers here:
Subtract 1 day with PHP
(9 answers)
Closed 7 years ago.
I have to compute a specific date considering the number of days I want to substract.
My code looks roughly like this:
$datac = date("Y-m-d");
$data = strtotime("-1 day" ,$datac);
But the output is: -84384
I don't understand what I do wrong.
It should work something like date -1 and show the date from yesterday. Thank you!
$datac = new DateTime();
$datac->modify('-1 day');
$data = $datac->format('Y-m-d');
$datac = date("Y-m-d");
$data = date("Y-m-d", strtotime('-1 day' . $datac));

how to add manual value to date() function [duplicate]

This question already has answers here:
Adding days to $Date in PHP
(12 answers)
Closed 8 years ago.
I m in need of adding a defined value to the date() function.
I just want to add 2 more days with the date() function.
suppose date("Y-m-d H:i:s"); //2014-06-12 05:38:50
I just want to add 2 more days with the day value which is 12 on above example.
can anyone help ?
use php DateTime Object like :
$date = new DateTime();
$date->add(new DateInterval('P2D'));
echo $date->format('Y-m-d H:i:s') . "\n";

find the last day/date of a WEEKOFYEAR with php [duplicate]

This question already has answers here:
How to get the first day of a given week number in PHP (multi-platform)?
(9 answers)
Closed 9 years ago.
I have a value that is the number for the weekofyear (between 1-52 ). I want to find out the date (yyyy-mm-dd) for the last day of that week.
I would prefer to do it in PHP rathe then MYSQL.
This can be easily solved with DateTime::setISODate() method:
$week = 50;
$dt = new DateTime();
$dt->setISODate($dt->format('o'), $week, 7);
echo $dt->format('Y-m-d');
demo
Or you can just create DateTime object (or unix timestamp with strtotime()) with ISO-8601 format like 2014-W50-7:
$week = 50;
$iso = sprintf("2014-W%02d-7", $week);
$dt = new DateTime($iso);
echo $dt->format('Y-m-d');
echo date('Y-m-d', strtotime($iso)); # or using strtotime()
demo

php get oldest record and add 1 week [duplicate]

This question already has answers here:
php date format YYYY-MM-DD minus or add one week from now?
(4 answers)
Closed 9 years ago.
I'm looking at making an automated post once a week blog so I can create more postings and then have them go out once a week. I'm having some trouble getting the greatest time and adding 1 week to it.
My database I'm using "datetime".
So the string is in "2013-03-20 09:42:41".
I can get the value of greatest post blog_date, but how do I add 1 week to the string?
date('$blog_date', strtotime("+1 week"));
Thanks for your time ^^
ANSWER WORKS:
$blog_date = date('Y-m-d h:i:s', strtotime("+1 week", strtotime($newest)));
You can use the Datetime object to add a week easily
http://php.net/manual/en/book.datetime.php
$date = new DateTime('2013-03-20 09:42:41');
$date->modify('+1 week');
Try this..
$blog_date = "2013-03-20 09:42:41";
$date2 = strtotime(date("Y-m-d", strtotime($blog_date)) . "+1 week");
echo date('Y-m-d', $date2);
Output
2013-03-27

Categories