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 want to update a date in a table using a prepared statement. The date is in DD/MM/YY format in the form, and so I need to get it into YYYY-MM-DD format for my MySQL database. So I'm trying to use the STR_TO_TIME() function.
However, I can't work out how to include it in my query when using a (procedural) prepared statement, and I can't find any examples online. Can anyone help? Or is there a better way to do it with PHP?
Use DateTime.
$date = '07/01/14';
$dt = DateTime::createFromFormat('d/m/y', $date);
echo $dt->format('Y-m-d'); // 2014-01-07
Take a look at the PHP Documentation http://www.php.net/manual/en/datetime.format.php
Object oriented style
<?php
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');
?>
Procedural style
<?php
$date = date_create('2000-01-01');
echo date_format($date, 'Y-m-d H:i:s');
?>
Related
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
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
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"));
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.
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);