$firstDayUTS = mktime [0, 0, 0, date["m"], 1, date["Y"]];
$lastDayUTS = mktime [0, 0, 0, date["m"], date['t'], date["Y"]];
$firstDay = date["d-m-Y", $firstDayUTS];
$lastDay = date["d-m-Y", $lastDayUTS];
Write a PHP script to get the first and last day of a month from a specified date. Sample Solution: PHP Code: Sample Output: Flowchart : PHP Code Editor: Have another way to solve this solution? Contribute your code [and comments] through Disqus. Previous: Write a PHP script to calculate number of days between two dates.PHP date: Exercise-8 with Solution
First day : 2008-02-01 - Last day : 2008-02-29
Next: Write a PHP script to print like : Saturday the 7th
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
PHP: Tips of the Day
PHP: How to push both value and key into PHP array?
No, there is no array_push[] equivalent for associative arrays because there is no way determine the next key.
You'll have to use
$arrayname[indexname] = $value;
Ref : //bit.ly/3cp9Gij
- Exercises: Weekly Top 16 Most Popular Topics
- SQL Exercises, Practice, Solution - JOINS
- SQL Exercises, Practice, Solution - SUBQUERIES
- JavaScript basic - Exercises, Practice, Solution
- Java Array: Exercises, Practice, Solution
- C Programming Exercises, Practice, Solution : Conditional Statement
- HR Database - SORT FILTER: Exercises, Practice, Solution
- C Programming Exercises, Practice, Solution : String
- Python Data Types: Dictionary - Exercises, Practice, Solution
- Python Programming Puzzles - Exercises, Practice, Solution
- C++ Array: Exercises, Practice, Solution
- JavaScript conditional statements and loops - Exercises, Practice, Solution
- C# Sharp Basic Algorithm: Exercises, Practice, Solution
- Python Lambda - Exercises, Practice, Solution
- Python Pandas DataFrame: Exercises, Practice, Solution
- Conversion Tools
- JavaScript: HTML Form Validation
Hi Guys,
In this example,I will learn you how to get the first day of specific month in php.you can easy and simply get the first day of specific month in php.
Sometimes we need How to get the first day of a month from a specific date in php for various purposes. We can do it in many ways.
Example:
Output:
2021-01-01
It will help you...
#PHP
✌️ Like this article? Follow me on Twitter and Facebook. You can also subscribe to RSS Feed.
Get First Day Of Current Month Php With Code Examples
In this session, we’ll try our hand at solving the Get First Day Of Current Month Php puzzle by using the computer language. The code that follows serves to illustrate this point.
$first_day = date['Y-m-01']; $last_day = date['Y-m-t'];
The issue with Get First Day Of Current Month Php can be solved in a variety of ways, all of which are outlined in the list that follows.
//get first day of the current month $start = date["Y-m-1 00:00:00"]; //get current date of the month $end = date["Y-m-d H:i:s"]; //query data for the current month so far $query = $this->db_model->run_query["select column_1, column_2 from table where date_column BETWEEN '".$start."' AND '".$end."'"];
$config_month = 1; $config_day = 1; $new_expiry_date = date['Y-m-d', mktime[0, 0, 0, date['m'] + $config_month, 1 + $config_day, date['Y']]];
We investigated a wide range of use cases in order to find a solution to the Get First Day Of Current Month Php problem.
How to get 1st date of current month in php?
php echo 'First Date = ' . date['Y-m-01'] .In the examples above:
- Y gives you the 4-digit year from the timestamp ['2010']
- m gives you the numeric month from the timestamp, with a leading zero ['04']
- t gives you the number of days in the timestamp's month ['30']
How to get day of month in php?
The PHP function cal_days_in_month[] returns the number of days for a given month and year.
How can I get first date and date of last month in php?
php get start and end date of month and year