Get Last Friday - CSharp System

CSharp examples for System:DateTime Day

Description

Get Last Friday

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/* w  w  w  . j av  a 2 s  .co  m*/

public class Main{
        private static DateTime GetLastFriday(DateTime d)
        {
            DateTime dd = new DateTime(d.Year, d.Month, d.Day, 15, 05, 0);
            int c = 0;
            if (d.DayOfWeek >= DayOfWeek.Friday)
            {
                c = 5 - (int)d.DayOfWeek;

            }
            if (d.DayOfWeek < DayOfWeek.Friday)
            {
                c = -2 - (int)d.DayOfWeek;
            }
            return GetEndTradeTime(dd.AddDays(c));
        }
}

Related Tutorials