Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace prog1
- {
- class Program
- {
- static void WorkTime(DateTime dateOfEmployment,DateTime Time)
- {
- var dateofEmployement = dateOfEmployment;
- var NowTime = Time.AddDays(1);
- var Months = (NowTime.Year - dateofEmployement.Year) * 12 + NowTime.Month - dateofEmployement.Month;
- Months += NowTime.Day < dateofEmployement.Day ? -1 : 0;
- var yearsOfEmployment = Months / 12;
- var monthsOfEmployment = Months % 12;
- var daysOfEmployment = NowTime.Subtract(dateofEmployement.AddMonths(Months)).Days;
- Console.WriteLine(yearsOfEmployment + "y " + monthsOfEmployment + "m " + daysOfEmployment + "d ");
- }
- static void Main(string[] args)
- {
- var dateofEmployement = new DateTime(2016, 07, 01);
- var TimeS = new DateTime(2021, 02,11);
- WorkTime(dateofEmployement,TimeS);
- }
- }
- }
Add Comment
Please, Sign In to add comment