Get day number from Date format by php [duplicate] - php

This question already has answers here:
How to extract only 'Day' value from full 'Date' string?
(7 answers)
Closed 2 years ago.
I have a date Formate from database number 2020-11-15 I want to get only the day number. I tried the following.
$your_date = '2020-11-15';
$ar_day2 = date("D", strtotime($your_date)); //The value is (Sun)
I am looking for result '15'.
Is there way by php?

use small d
$ar_day2 = date("d", strtotime('2020-11-15'));
echo $ar_day2 = date("d", strtotime('2020-11-15')); // will give => 15
echo $ar_day2 = date("D", strtotime('2020-11-15')); // will give => Sun

Related

Function to add 1 day to date using php [duplicate]

This question already has answers here:
adding 1 day to a DATETIME format value
(9 answers)
Closed 4 years ago.
I have tring that contain date
i.e: 2018-07-18
Is there any function that get the string and add 1 day, so the result should be: 2018-07-19
This should work:
$date = "2018-07-18";
$new_date = date('Y-m-d', strtotime($date. ' + 1 days'));

PHP separate variable container [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
I have a variable that contains a date
$date = "04/18/2017 04:02 PM";
This comes from a date field, This field will always contain a date like this, and What I'm trying to do is separating the date from the time
So how do i go about getting only 04/18/2017 from the variable or the time 04:02 PM ?
Thanks.
Just do a simple explode:
$explode = explode($date, ' ', 2);
$date = $explode[0];
$time = $explode[1];

Php get month number from string with date [duplicate]

This question already has answers here:
Get month of a given date
(6 answers)
Closed 7 years ago.
i have a string in this format '2015-4-28'
How i get month number for this string ( the value in this example is 4)?
Thanks
Another option would be to do this:
date('m', strtotime($date));
Change the m to an n to get the month without the leading 0.
With this:
<?php
$a = "2015-4-28";
$parts= explode("-", $a);
echo $parts[0]; // 2015
echo $parts[1]; // 4
echo $parts[2]; // 28
?>

Take PHP variable value of 201501 for example and display January 2015 [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 8 years ago.
I have a date value that is being passed as 201501.
How could I take that and display January 2015 instead?
It's being passed through a PHP variable.
Just try with:
$input = '201501';
$output = DateTime::createFromFormat('Ym', $input)->format('F Y');
Try below code
$data = '201501';
$monthNum = substr($data,4);
$year = substr($data,0,4);
$dateObj = DateTime::createFromFormat('!m', $monthNum);
$monthName = $dateObj->format('F');
echo $monthName.' '.$year;

Converting month name in given date into month number [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP date format converting
I have a date like 2012-september-09. How to convert this into 2012-09-09 using PHP?
You can try with strptime
$date = '2012-september-09';
$strp = strptime($date, '%Y-%B-%d');
$ymd = sprintf('%04d-%02d-%02d', $strp['tm_year'] + 1900, $strp['tm_mon'] + 1, $strp['tm_mday']);
$new_date = new DateTime($ymd);
echo $new_date->format('Y-m-d');
here's a Codepad
Try this
Change
<?php echo date('Y-m-d',strtotime('2012-september-09'));?>
To
<?php echo date('Y-m-d',strtotime('09-september-2012'));?>

Categories