Set the initial "current" time in PHP [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm having an application in PHP which I want to foresight how it works in certain situations which I need to rewind the time to the future.
Is there any ways to do this?
I could only find timezone function which let me change the time zone but what I want us to change it to the future like... 3weeks or something like that.

There are a bunch of ways to do this with PHP. Here's one:
$future = date("Y-m-d", strtotime("+3 weeks"));
Here's another:
$future = (new DateTime())->modify("+3 weeks")->format("Y-m-d");
Here's another:
$future = (new DateTime())->add(new DateInterval("P21D"))->format("Y-m-d");

Sounds like a job for fluxcapacitor if you're running on Linux

You can do it with
date('l jS F (Y-m-d)', strtotime('3 week'));
or
date('l jS F (Y-m-d)', strtotime('21 days')); // for future 3 weeks

Related

Display DD/MM/YYYY PHP echo from Database [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Anyone knows how to pull and display the date a member sign up through your website using phpmyadmin following the format: DD/MM/YYYY example: <?php echo $row->date; ?> maybe? I am assuming something similar to this will work: echo date("l jS \of F Y h:i:s A"); but would be more the date a member joined not the current date.
Any help is greatly appreciated,
if $row->date is some date/time string, one way would be to use strtotime.
$time = strtotime($row->date);
//then use the date function as you need
$date = date('d/m/Y', $time);
echo $date;
if you want an sql query
SELECT date(date,%d/%m/%Y) FROM tbl_name

Calculate time stamp from date and time given by user [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my application, the user gives 2 inputs — one is date and the other is time:
$date = date("d-M-Y");
$time=date("h:m:s");
How can I calculate a time stamp from these two variables in PHP?
actually i take the date form date picker and time from time oicker.....
If you want time stamp then use this
echo strtotime($date.' '.$time);

How to convert a PHP date string to another format [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I've a string like "2013-05-07"
and I want to convert it in "7 May 2013" via any functional way (if available) or in short method as possible
$dt = new DateTime('2013-05-07');
echo $dt->format('j F Y');
As of PHP 5.4
echo (new DateTime('2013-05-07'))->format('j F Y');
PHP Date Format
echo date('j F Y', strtotime("2013-05-07"));

strtotime() and easter_date() won't work together [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I'm trying to get the day after the easter date:
date("d-m-y", strtotime(easter_date(), '+1 day'));
I don't understand, the date showed is still the same, but when I try this:
date("d-m-y", strtotime('+1 day'));
It works.
How can I do?
That's because easter_date() produces a unix timestamp:
1364713200
And strtotime() is meant for this like 'today' and 'tuesday next week';
If you just want to add a day to it, just add 86400 (this is how many seconds are in a day) to easter_date();
So: date("d-m-y", easter_date() + 86400);
The function easter_date() returns a UNIX timestamp (e.g. 123338898) whereas strtotime()'s first parameter must be a valid date/time string (e.g. 2013-05-30 23:59:59). Valid formats are explained in Date and Time Formats.
Additionally, from the PHP documentation for strtotime():
Using this function for mathematical operations is not advisable. It
is better to use DateTime::add() and DateTime::sub() in PHP 5.3 and
later, or DateTime::modify() in PHP 5.2.

how to increment the current date which is in d/m/Y format by one month [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i want to increment the current date by one month which is in d/m/Y format
but i have no idea about this,can any one give me a relevant example.
thanks in advance
In PHP you do this:
$time = strtotime("+1 month", time());
$date = date("d/m/Y", $time);

Categories