Previous month name

#1
[eluser]Sawariya[/eluser]
hi friends how to get previous month name according to server date...??
anybody can help me??
thanks in advance

#2
[eluser]Lone[/eluser]
All you need to know on this is at the following link PHP.net Date Function

#3
[eluser]ejangi[/eluser]
You could do something to the effect of:
Code:
$month_name = date('F', (time()-(60*60*24*30)));

It's a bit hack-ish, but it should work and may spark a better solution.

#4
[eluser]Lone[/eluser]
Ok, you got me thinking on this and its not that easy to achieve in one line really because if month is January then current month less one is 0 not 12.

ucantblamem's solution is a good quick fix but the issue is obvious that not all months have 30 days...

Heres the best solution I could come up with - any suggestions welcome (such as something cleaner then mktime?).

Code:
if( ($monthPrevious = 1-1) == 0) {
    $monthPrevious = 12;
}

$monthPreviousName =  date('F',mktime(0,0,0,$monthPrevious,1,2000));

A previous date function in the date helper could come handy looking at this Smile

#5
[eluser]xwero[/eluser]
how about
Code:
date('F',strtotime("-1 month"));

#6
[eluser]ejangi[/eluser]
Lol, good man - short and to the point, I like it! Big Grin

#7
[eluser]Lone[/eluser]
xwero wins!

strtotime is such a magical function at times Tongue


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.