php - Set day to "first day of month", if it's set, set to previous month -
i want set first day of month (y-m-01) if day > 1. if day first day of month, should give me "-1 month" instead. same should able happen when going forward. (+1 month)
how manage in php?
(update) got code working going backwards can't use same method going forward last day of month 28, 29, 30 or 31. should using last day of month instead don't know how to..
if (date("j", strtotime('today', $time)) == 1) { $beginmon = strtotime('first day of last month', $time); } else { $beginmon = strtotime('first day of month', $time); }
sounds simple
<?php if(date("j")>1) { echo date("y-m-01"); } else { echo date("y-m-d",strtotime("-1 month")); } ?>
edit
can modified environment as
<?php if(date("j")==1) { $beginmon = strtotime(date("y-m-01")); } else { $beginmon=strtotime("-1 month"); } ?>
Comments
Post a Comment