Twig date difference

Since PHP 5.3 There is another option without to write an extension. This example show how to calc the plural day/days {# endDate and startDate are strings or DateTime objects #} {% set difference = date(endDate).diff(date(startDate)) %} {% set leftDays = difference.days %} {% if leftDays == 1 %} 1 day {% else %} {{ …

Read more

Get the complete month name in English

You can pass a CultureInfo object as an argument DateTime.ToString(): CultureInfo ci = new CultureInfo(“en-US”); var month = DateTime.Now.ToString(“MMMM”, ci); // alternatively you can use CultureInfo.InvariantCulture: var month = DateTime.Now.ToString(“MMMM”, CultureInfo.InvariantCulture);

Measure execution time in C#

The Stopwatch class is specifically designed to measure elapsed time and may (if available on your hardware) provide good granularity/accuracy using an underlying high-frequency hardware timer. So this seem the best choice. The IsHighResolution property can be used to determine whether high resolution timing is available. Per the documentation, this class offers a wrapper on …

Read more