Get tomorrows date from the webpage - php

What is a php function that i can make call tomorrows date formatted like this? 02/04/2014
So if im looking at the website on 2/3/2014 it will show 02/04/2014
If i look at it on 2/15/2014 it will show 2/16/2014

Just add using strtotime() / date() functions:
echo date('m/d/Y', strtotime('+1 day'));
Update
You can also do it using PHP's DateTime and DateInterval classes:
$date = new DateTime();
$date->add('P1D');
echo $date->format('m/d/Y');

This should work ..
<?php
function tomorrow()
{$date = date('m/d/Y');
sleep(24*60*60);
return $date;}
echo tomorrow();
?>

Related

get date from dateTime in PHP

I want to extract date without time from a single value from array result thaht I got.
I tried using array_slice but it didn't work.
My code..
$dateRows = $this->get('app')->getDates();
$dateRow = json_decode(json_encode($dateRows[0], true));
dump($dateRow[0]);die;
And I got result..
"2014-01-01 00:00:00"
And I want it to return just
"2014-01-01"
Very Simple, just use date_create() on your date & then format it using date_format() as follows -
$date = date_create("2014-01-01 00:00:00");
echo date_format($date,"Y-m-d");
So, in your case, it would be something like -
$date1 = date_create($dateRows[0]);
echo date_format($date1,"Y-m-d");
you can use strtotime function as well for getting formatted data
$a = "2014-01-01 00:00:00";
echo date('Y-m-d', strtotime($a));

Convert date and time to only year in php

I have a variable is which the value coming is Date along with time in php. How do I convert it into a variable to get only the year? I do not need automatic updation but the format change is needed. Normal answers are giving it about date but my variable is containing time as well.
The format coming by now is 2017-12-11 4:06:37 and i need only 2017
Use like this:
<?php echo date('Y',strtotime('now'));?>
You can you simple DateTime function and date_formate() function for displaying separate year, month and date.
For that you have to first convert in Object of your current Date time string by using :
$date = new \DateTime('2017-12-11 4:06:37');
And then you can use date format function by using below code:
echo date_format($date, "Y"); //for Display Year
echo date_format($date, "m"); //for Display Month
echo date_format($date, "d"); //for Display Date
You can code like this (working perfectly):
$format = 'Y-m-d H:i:s';
$date = DateTime::createFromFormat($format, '2009-02-15 15:16:17');
echo "Format: $format; " . $date->format('Y') . "\n";
As mentioned by Himanshu Upadhyay, this is correct and the easiest way.
<?php
echo date('Y',strtotime('now'));
?>
But i would recommend you to read this here. You should really do actually!
By using DateTime class
$date = new \DateTime('2017-12-11 4:06:37');
echo $date->format('Y');

Changing date format from MySQL in php

Currently, this code : <?php echo $user->last_login?> is showing this date format YYYY-MM-DD from MySQL. How do i change it to this format DD-MM-YYYY?
Thanks.
Edit : Problem solved. $date = new DateTime($user->last_login);
echo $date->format('Y-m-d H:i:s');
Thanks guys!
You can do this:
date(d-m-Y", strtotime($user->last_login));
Or this:
$date = new DateTime($user->last_login);
echo $date->format('d-m-Y');
Or use Carbon (http://carbon.nesbot.com/docs/):
Carbon::createFromFormat('Y-m-d', $user->last_login)->format('d-m-Y');
Actually #frayne-konok was close. You'll need to do
echo date('d-m-Y', strtotime($user->last_login));
See the PHP docs for more date formatting codes: http://php.net/manual/en/function.date.php

How to get current date in codeigniter

How to get current date in codeigniter in YY-mm-dd format. I wants to get current date in YY-mm-dd frmat and put this value into input text box
You can use the PHP date function.
date('Y-m-d');
Up to my knowledge, there is no separate date function in codeigniter.
EDIT :
But if you want date in this format 13-04-05 [ yy-mm-dd ], Try this
date('y-m-d');
For more date formats, check this link PHP Date Formats
Try to use this is a generic format of DateTime
echo date('Y-m-d H:i:s');
use php date function
echo date("Y-m-d");
will give you the result
What about:
$date = new \Datetime('now');
var_dump($date);
if you want the full date:
echo date('Y-m-d');
depends your date structure.
echo date('d-m-Y');
if you want year only, then echo date('Y'); is enough
Use php date() function, like this
echo Date('Y/m/d');
it give you the desired result!

How to format date using php to query Google Calendar feed?

I have an events feed that needs the dates in this format.
query.setMinimumStartTime("2011-12-15");
query.setMaximumStartTime("2011-12-19");
When I pull from the database <?php $startmin = $line['StartDate'];?>
it comes in this format "12/15/2011"
I use <?php $fstartmax = str_replace('/','-',$startmax);?>
to change the "/" to "-" and now have 12-15-2011
how can I make it 2011-12-15??
$date = new DateTime('12/15/2011');
$interval = new DateInterval('P1D');
$date->add($interval);
echo $date->format('Y-m-d');
See http://fr2.php.net/manual/en/class.datetime.php & http://fr2.php.net/manual/en/class.dateinterval.php for more info.
You can use strtotime() to get a timestamp and then date with the resulting timestamp, like so:
echo date("Y-m-d", strtotime("12/15/2011"));

Categories