Home > development, error, event handlers, MOSS, MS SharePoint Sever, sharepoint, sps > DateTime and Days of the Week

DateTime and Days of the Week

Playing around with DateTime and Days of the Week:


if (DateTime.Now.ToString("ddd") == "Thu" || DateTime.Now.ToString("ddd") == "Fri")
            {
                DateTime dateTime = DateTime.Now.AddDays(Convert.ToDouble(days) + 2);
                dateTime = dateTime.AddHours(Convert.ToDouble(hours));
                dateTime = dateTime.AddMinutes(Convert.ToDouble(mins));
                return dateTime;
            }
            else if (DateTime.Now.ToString("ddd") == "Sat" || DateTime.Now.ToString("ddd") == "Sun")
            {
                DateTime dateTime = DateTime.Now.AddDays(Convert.ToDouble(days) + 1);
                dateTime = dateTime.AddHours(Convert.ToDouble(hours));
                dateTime = dateTime.AddMinutes(Convert.ToDouble(mins));
                return dateTime;
            }
            else
            {
                DateTime dateTime = DateTime.Now.AddDays(Convert.ToDouble(days));
                dateTime = dateTime.AddHours(Convert.ToDouble(hours));
                dateTime = dateTime.AddMinutes(Convert.ToDouble(mins));
                return dateTime;
            }


//---------------------------------------------------------------------------------------------------



            DateTime dateTime = DateTime.Now.AddDays(Convert.ToDouble(days));
            dateTime = dateTime.AddHours(Convert.ToDouble(hours));
            dateTime = dateTime.AddMinutes(Convert.ToDouble(mins));

            switch (dateTime.ToString("ddd"))
            {
                case "Sat":
                    {
                        dateTime = dateTime.AddDays(2);
                        return dateTime;
                    }
                case "Sun":
                    {
                        dateTime = dateTime.AddDays(Convert.ToDouble(days) + 1);
                        return dateTime;
                    }
                default:
                    {
                        return dateTime;
                    }
            }

Hope this helps–
Rehman.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: