Work with a time span in Javascript

Sounds like you need moment.js e.g. moment().subtract(‘days’, 6).calendar(); => last Sunday at 8:23 PM moment().startOf(‘hour’).fromNow(); => 26 minutes ago Edit: Pure JS date diff calculation: var date1 = new Date(“7/Nov/2012 20:30:00”); var date2 = new Date(“20/Nov/2012 19:15:00”); var diff = date2.getTime() – date1.getTime(); var days = Math.floor(diff / (1000 * 60 * 60 * 24)); … Read more

Why does TimeSpan.FromSeconds(double) round to milliseconds?

As you’ve found out yourself, it’s a documented feature. It’s described in the documentation of TimeSpan: Parameters value Type: System.Double A number of seconds, accurate to the nearest millisecond. The reason for this is probably because a double is not that accurate at all. It is always a good idea to do some rounding when … Read more

Storing TimeSpan with Entity Framework Codefirst – SqlDbType.Time overflow

[Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete(“Property ‘” + nameof(Duration) + “‘ should be used instead.”)] public long DurationTicks { get; set; } [NotMapped] public TimeSpan Duration { #pragma warning disable 618 get { return new TimeSpan(DurationTicks); } set { DurationTicks = value.Ticks; } #pragma warning restore 618 } Update This is now achievable since EF Core 2.1, using … Read more

How convert TimeSpan to 24 hours and minutes String?

myTimeSpan.ToString(@”hh\:mm”) Custom TimeSpan Format Strings The custom TimeSpan format specifiers do not include placeholder separator symbols, such as the symbols that separate days from hours, hours from minutes, or seconds from fractional seconds. Instead, these symbols must be included in the custom format string as string literals. For example, “dd.hh\:mm” defines a period (.) as … Read more

Merge pandas dataframes where one value is between two others [duplicate]

As you say, this is pretty easy in SQL, so why not do it in SQL? import pandas as pd import sqlite3 #We’ll use firelynx’s tables: presidents = pd.DataFrame({“name”: [“Bush”, “Obama”, “Trump”], “president_id”:[43, 44, 45]}) terms = pd.DataFrame({‘start_date’: pd.date_range(‘2001-01-20′, periods=5, freq=’48M’), ‘end_date’: pd.date_range(‘2005-01-21′, periods=5, freq=’48M’), ‘president_id’: [43, 43, 44, 44, 45]}) war_declarations = pd.DataFrame({“date”: [datetime(2001, … Read more

Format TimeSpan greater than 24 hour

Well, the simplest thing to do is to format this yourself, e.g. return string.Format(“{0}hr {1}mn {2}sec”, (int) span.TotalHours, span.Minutes, span.Seconds); In VB: Public Shared Function FormatTimeSpan(span As TimeSpan) As String Return String.Format(“{0}hr {1}mn {2}sec”, _ CInt(Math.Truncate(span.TotalHours)), _ span.Minutes, _ span.Seconds) End Function I don’t know whether any of the TimeSpan formatting in .NET 4 would … Read more

What is the easiest way to subtract time in C#?

These can all be done with DateTime.Add(TimeSpan) since it supports positive and negative timespans. DateTime original = new DateTime(year, month, day, 8, 0, 0); DateTime updated = original.Add(new TimeSpan(5,0,0)); DateTime original = new DateTime(year, month, day, 17, 0, 0); DateTime updated = original.Add(new TimeSpan(-2,0,0)); DateTime original = new DateTime(year, month, day, 17, 30, 0); DateTime … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)