Entrepreneur, Web Developer and Facilitator from God's Own Country

Last date of a month in php

  • Share

I have came across some crazy snippets of code finding the last day of a month in php. Then I came across this very simple method. PHP date function takes a paramater as ‘t’ which gives the number of days of a month which is the last day Winking smile

so

<?php
echo date(‘Y-m-t’)';
?>

will give you the last day of the month

You can use the same method to find the last method of any month/year using strtotime

<?php
echo date(‘Y-m-t’, strtotime(‘next month’));
?>

Peace of cake right Smile

2 comments

  1. ty for sharing…your are the “man”…:)

Leave a Reply