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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.