C# – Get the current date and time

Use DateTime.Now to get the current date/time, like this: This outputs the system’s current date/time: Note: By default, it uses the current culture’s date format (from the OS). This is showing the US date format – MM/dd/yyyy. DateTime.Now is the local date/time from the system where the code is executing. Keep that in mind if … Read more

C# – Round up to the nearest 30 minutes

Here’s how to round a DateTime up to the nearest 30 minutes: When the time is 3:38 pm, it rounds to 4:00 pm. When it’s 5:03 pm, it rounds to 5:30 pm. When it’s exactly 2:00 pm, it’ll round up to 2:30 pm (note: see the What if you’re at the start of a 30 … Read more