How to calculate PercentOf in PHP

To calculate PercentOf in PHP you can use the following snippet. It will calculate the percent of 2 given integers.

Sample PHP

Function PercentOf($int1, $int2) { 
	if ($int2 <= 0 || $int1 <=0){
		return 0;
    $val1 = $int1 / $int2;  
    $retVal = $val1 * 100;  
    return $retVal;  

If there is a 0 passed it will return 0.

How to calculate the number of days in a month in C# and VB.NET

To calculate the number of days in a month in C# and VB.NET.

Sample C#

private static int DayCountPerMonth(DateTime date)
	if (date == null) {  throw new ArgumentNullException();}
	var calendar = new System.Globalization.GregorianCalendar();
	return calendar.GetDaysInMonth(date.Year, date.Month);

Sample VB.NET

Private Shared Function DayCountPerMonth(date As DateTime) As Integer
	If date Is Nothing Then
		Throw New ArgumentNullException()
	End If
	Dim calendar = New System.Globalization.GregorianCalendar()
	Return calendar.GetDaysInMonth(date.Year, date.Month)
End Function

How to calculate a person’s age using C# and VB.NET

This code snippet can help you to calculate a Person’s age using C# and VB.NET.

C# Snippet

VB.NET Snippet

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links: DateTime Structure, DateTime Methods

working .NET 2.0
working .NET 3.0
not tested .NET 3.5
not working .NET 4.0
not working .NET 4.5