Skip to content

Instantly share code, notes, and snippets.

@hidayat365
Created December 6, 2013 04:09
Show Gist options
  • Save hidayat365/7818428 to your computer and use it in GitHub Desktop.
Save hidayat365/7818428 to your computer and use it in GitHub Desktop.
Contoh penggunaan TimeSpan di c#
private string HitungUsia(DateTime awal, DateTime akhir)
{
TimeSpan selisih = akhir.Subtract(awal);
int tahun = Convert.ToInt32(selisih.Days / 365);
int bulan = Convert.ToInt32(selisih.Days % 365 / 30);
int hari = selisih.Days - tahun * 365 - bulan * 30;
return String.Format("Usia {0} tahun {1} bulan {2} hari", tahun, bulan, hari);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment