Get the day from a very simple date - php

Is there a simple way to get the day from a very simple date string?
For example:
14 mar 2012
gets converted to:
Wed, 14 mar 2012

You should familiarize yourself with DateTime:
$str = "14 mar 2012";
$date = DateTime::createFromFormat("j M Y", $str);
$str = $date->format("D, j M Y");

$dateUnformated = '14 mar 2012';
$dateFormated = date("D, j M Y", strtotime($dateUnformated));

Related

How can I change the day format from "Monday" to "Mon" with moment.php?

https://github.com/fightbulc/moment.php/tree/master/src
$m = new \Moment\Moment();
echo $m->format('l M d h:i');
My output:
Wednesday Nov 08 09:19
What I try to achieve:
Wed Nov 08 09:19
D is stands for 3 character Day name.
So change your code to :
echo $m->format('D M d h:i');

Php string date a date into another format?

Hi I want change date string -> Sat Oct 04 00:00:00 GMT+05:30 2008 -> into 'Y-m-d H:i:s' format my code is as below :
$lsd = strtotime($vehicle->newDate);
$newDate = date('Y-m-d H:i:s',$lsd);
I am getting date like 1970-01-01 05:30:00 Why is so ?
I have gone through reference : http://php.net/manual/en/function.date.php
I have got date fromat representation labels for all except GMT+05:30
Sat Oct 04 00:00:00 GMT+05:30 2008
D M d H:i:s o
Instead of down-votes if that one label I get then I will be thankful then I will use http://php.net/manual/en/datetime.format.php,
Use this one.
$lsd = strtotime("Sat Oct 04 00:00:00 GMT+05:30 2008");
$newDate = date('Y-m-d H:i:s',$lsd);
echo $newDate;
Try this
$lsd = strtotime($vehicle->newDate);
$newDate = date("D M j G:i:s T Y");

how to get this type of date in php like this Date {Fri Jun 24 2016 10:30:06 GMT+0530 (IST)} jquery standerd format

How to get this type of date in PHP like this
Date {Fri Jun 24 2016 10:30:06 GMT+0530 (IST)}
jQuery standerd format.
Try:
Also refer http://php.net/manual/en/function.date.php for different date formats
echo date("D M d Y h:i:s eO T");
Output:
Fri Jun 24 2016 10:52:42 Asia/Calcutta+0530 IST
As you were looking for ยป RFC 2822 formatted date you can simply use
echo date("r"); // Fri, 24 Jun 2016 10:59:36 +0530
Or if you want to be somewhat like as question you can use
echo date("D M d Y H:i:s eO T"); // Fri Jun 24 2016 10:59:37 Asia/Kolkata+0530 IST
Docs
In PHP you can get this format as
<?php
$tzone = new DateTimeZone('Asia/Calcutta');
$dtime = new DateTime("now", $tzone);
echo $dtime->format("D M d Y H:i:s \G\M\TO (T)");
?>
In that case you will get the output:
Fri Jun 24 2016 11:25:40 GMT+0530 (IST)
That is your output as you wanted.
finally got it .... thanks for help..
$tzone = new DateTimeZone('Asia/Calcutta');
$dtime = new DateTime("now", $tzone);
$daet = $dtime->format("D M d Y H:i:s \G\M\TO (T)");
$timestart = explode (' ', microtime());
$timeInSecond = substr($timestart[0],1,4)."Z";
echo preg_replace('/\+.*/',$timeInSecond,date('c',"1466774626"));
//2016-06-24T15:23:46.541Z

Adding time to Nov. 2nd gives error

I'm having some problems adding a date.
$test = strtotime('nov 02 2014');
$test_date = date('D, M. jS, Y' ,(1.0*86400) + $test);
echo $test_date;
returns Sun, Nov. 2nd, 2014
changing input to nov 01 and nov 03 return the expected strings.
This should work for you:
$test = "nov 02 2014";
echo $test_date = date('D, M. jS, Y' ,strtotime($test . ' + 1 day'));
Daylight Saving Time ended on November 2, 2014. This means that November 2, 2014 lasted longer than the 86,400 seconds you're adding to the date!

Convert date in php

How to convert "Thu Oct 28 16:33:29 +0000 2010 " to like "Oct 28,2010 at 10:33PM"
Use the strtotime function combined with the date function
echo date("jS F, Y", strtotime("11/25/10"));
// outputs 25th November, 2010
$date = DateTime::createFromFormat('Thu Oct 28 16:33:29 +0000 2010', 'D M j h:m:s O Y');
echo $date->format('M d,Y, h:mA');
Relevant docs here

Categories