Get weekday/day-of-week for Datetime column of DataFrame

Use the new dt.dayofweek property: In [2]: df[‘weekday’] = df[‘Timestamp’].dt.dayofweek df Out[2]: Timestamp Value weekday 0 2012-06-01 00:00:00 100 4 1 2012-06-01 00:15:00 150 4 2 2012-06-01 00:30:00 120 4 3 2012-06-01 01:00:00 220 4 4 2012-06-01 01:15:00 80 4 In the situation where the Timestamp is your index you need to reset the index … Read more

How to get the week day name from a date?

SQL> SELECT TO_CHAR(date ‘1982-03-09’, ‘DAY’) day FROM dual; DAY ——— TUESDAY SQL> SELECT TO_CHAR(date ‘1982-03-09’, ‘DY’) day FROM dual; DAY — TUE SQL> SELECT TO_CHAR(date ‘1982-03-09’, ‘Dy’) day FROM dual; DAY — Tue (Note that the queries use ANSI date literals, which follow the ISO-8601 date standard and avoid date format ambiguity.)

Retrieve current week’s Monday’s date

I would strongly recommend using Joda Time instead (for all your date/time work, not just this): // TODO: Consider time zones, calendars etc LocalDate now = new LocalDate(); LocalDate monday = now.withDayOfWeek(DateTimeConstants.MONDAY); System.out.println(monday); Note that as you’ve used Monday here, which is the first day of the week in Joda Time, this will always return … Read more

Get the weekday from a Date object or date string using JavaScript

Use this function, comes with date string validation: If you include this function somewhere in your project, // Accepts a Date object or date string that is recognized by the Date.parse() method function getDayOfWeek(date) { const dayOfWeek = new Date(date).getDay(); return isNaN(dayOfWeek) ? null : [‘Sunday’, ‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’][dayOfWeek]; } You will … Read more