ilkist Posted May 17, 2012 Share Posted May 17, 2012 I'm trying to convert this ASP function into a working PHP function with no luck =( I want to ask if anyone out here knows how to do this, and I would love you forever if you did. Private Function getdate(beg, en) beginYear = Year(beg) endYear = Year(en) months = Array("0", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") If (beginYear < 1000) Then beginYear = beginYear + 1900 End If If (endYear < 1000) Then endYear = endYear + 1900 End If getdate = months(Month(beg)) & " " & day(beg) If Not Year(beg) = Year(en) Then getdate = getdate& (", " & beginYear) End If If Not Month(beg) = Month(en) Or Not Day(beg) = Day(en) Then getdate = getdate& (" - ") End If If Not Month(beg) = Month(en) Then getdate = getdate& (" " & months(Month(en))) If Day(beg) = Day(en) Then getdate = getdate& (" " & Day(en)) End If End If If Not Day(beg) = Day(en) Then getdate = getdate& (" " & Day(en)) End If getdate = getdate& (", " & endYear) End Function Quote Link to comment https://forums.phpfreaks.com/topic/262687-asp-prodigies-needed/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 17, 2012 Share Posted May 17, 2012 It would probably help if you gave an example of what the beg and en date format is going to be in your php script. Quote Link to comment https://forums.phpfreaks.com/topic/262687-asp-prodigies-needed/#findComment-1346400 Share on other sites More sharing options...
PFMaBiSmAd Posted May 17, 2012 Share Posted May 17, 2012 I know nothing about ASP, but inference works great in problem solving, the following should work (depending on the format of the supplied dates) - <?php function _getdate($beg,$en){ // assuming "YYYY-MM-DD" date format list($beginYear,$beginMonth,$beginDay) = explode('-',$beg); // split date into parts list($endYear,$endMonth,$endDay) = explode('-',$en); // split date into parts $months = Array("0", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); If($beginYear < 1000) $beginYear += 1900; If($endYear < 1000) $endYear += 1900; $getdate = $months[intval($beginMonth)] . " " . $beginDay; If($beginYear != $endYear){ $getdate .= ", " . $beginYear; } If($beginMonth != $endMonth || $beginDay != $endDay){ $getdate .= " - "; } If($beginMonth != $endMonth){ $getdate .= " " . $months[intval($endMonth)]; If($beginDay == $endDay){ $getdate .= " " . $endDay; } } If($beginDay != $endDay){ $getdate .= " " . $endDay; } $getdate .= ", " . $endYear; return $getdate; } echo _getdate('2011-04-01','2012-05-17'); Quote Link to comment https://forums.phpfreaks.com/topic/262687-asp-prodigies-needed/#findComment-1346412 Share on other sites More sharing options...
ilkist Posted May 18, 2012 Author Share Posted May 18, 2012 Thanks so much!! This looks much much better than what I came up with >< I really appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/262687-asp-prodigies-needed/#findComment-1346637 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.