Jump to content

ASP prodigies needed


ilkist

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/262687-asp-prodigies-needed/
Share on other sites

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');

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.