PHP Set format date
Just a function to change the format of a mysql date to the one you want to.
function setDate($L_date,$L_dateFormat="dd-mm-yyyy"){//sets a date in a format if(strlen($L_date)>0){ $L_arrTemp = split(" ",$L_date); $L_strDate = $L_arrTemp[0]; // 2007-07-21 year month day $L_arrDate = split("-",$L_strDate);// split date $L_strYear = $L_arrDate[0]; $L_strMonth = $L_arrDate[1]; $L_strDay = $L_arrDate[2]; if($L_dateFormat == 'yyyy-mm-dd'){//default return $L_arrTemp[0]; } elseif($L_dateFormat == "dd-mm-yyyy"){//day month year $returnDate = $L_strDay."-".$L_strMonth."-".$L_strYear; return $returnDate; } elseif($L_dateFormat == "mm-dd-yyyy"){//month day year $returnDate = $L_strMonth."-".$L_strDay."-".$L_strYear; return $returnDate; } } else return false; }
- How to create widgets for Open Classifieds 1.4.X
- WP-Datediff - Plugin for WordPress
- phpSEO - Class for better SEO in PHP
- Change the CSS of your site with JavaScript
- How to Tweet from PHP and short Url with bit.ly
- Saving Money on Vacations by Finding Cheap Airfare
- How Long Does It Take To Get My Tax Refund Back?
- Prosper com Loan Ordering Feature Request
- Avoiding Late Fees
Help sharing and Flatter me ;)

I think you can do the same this way:
date(‘d-m-Y’,strtotime($indate));
I’ve forgot to say that is from mysql date to other format xD now i think it’s not the same, or it will work too?
Yes, it will work too, I’m using it everyday :)
mmmmmm Yes I see it works as you said, but the problem is when the input is like “dd-mm-yyyy” then the function date returns 1919-1212-09090909 for example.
And for that script I needed to be able to do that xD
Yes, it only accepts “yyyy-mm-dd”, as your function do.
You can also do:
date(‘d-m-Y’,strtotime(implode(‘-’,array_reverse(explode(‘-’,$indate)))));
But yeah, it becomes a little messy…
I see you are using split function, is the same that “explode” but split is deprecated and will be removed on PHP6
Oh thanks on that one. I’ll change it now form OC…just for the future, thanks ;)