Find if current time falls in a time range

For checking for a time of day use: TimeSpan start = new TimeSpan(10, 0, 0); //10 o’clock TimeSpan end = new TimeSpan(12, 0, 0); //12 o’clock TimeSpan now = DateTime.Now.TimeOfDay; if ((now > start) && (now < end)) { //match found } For absolute times use: DateTime start = new DateTime(2009, 12, 9, 10, 0, … Read more

Check if a given time lies between two times regardless of date

You can use the Calendar class in order to check. For example: try { String string1 = “20:11:13”; Date time1 = new SimpleDateFormat(“HH:mm:ss”).parse(string1); Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(time1); calendar1.add(Calendar.DATE, 1); String string2 = “14:49:00”; Date time2 = new SimpleDateFormat(“HH:mm:ss”).parse(string2); Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(time2); calendar2.add(Calendar.DATE, 1); String someRandomTime = “01:00:00”; Date d = new SimpleDateFormat(“HH:mm:ss”).parse(someRandomTime); … 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