Days between dates: Difference between revisions
Content deleted Content added
Added Sidef |
Added C# |
||
Line 84: | Line 84: | ||
generic 2020-01-01 to 2020-03-01 = 60 |
generic 2020-01-01 to 2020-03-01 = 60 |
||
</pre> |
</pre> |
||
=={{header|C sharp}}== |
|||
<lang csharp>using System; |
|||
using System.Globalization; |
|||
public class Program |
|||
{ |
|||
public static void Main() => WriteLine(DateDiff("1970-01-01", "2019-10-18")); |
|||
public static int DateDiff(string d1, string d2) { |
|||
var a = DateTime.ParseExact(d1, "yyyy-MM-dd", CultureInfo.InvariantCulture); |
|||
var b = DateTime.ParseExact(d2, "yyyy-MM-dd", CultureInfo.InvariantCulture); |
|||
return (int)(b - a).TotalDays; |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
18187 |
|||
</pre> |
|||
=={{header|D}}== |
=={{header|D}}== |
||
<lang d>import std.datetime.date; |
<lang d>import std.datetime.date; |