AttributeError module ‘DateTime’ has no attribute ‘strptime’ The error “AttributeError module ‘DateTime’ has no attribute ‘strptime’” occurs when you call the strptime() method on Python’s datetime module – rather than the datetime class inside it. Here’s what it looks like: If you get the above …
Await is only valid in Async functions. This syntax error occurs when you use an await expression outside an async execution context, like an async function or top-level body of an ES module (top-level await). Here’s what it looks like: How to solve “await is only valid …
If you need a cross-browser approach to convert a dd/mm/yyyy string to a Date object in JavaScript, here’s what you need to do: Split the date/time components into separate values (year, month, day, hour, minutes, etc.) Create a Date object with these arguments (details below). …
The error “TypeError: getElementById is not a function” happens for two common reasons (Based on StackOverflow users): The capitalization of “Id” isn’t correct Calling getElementById() on an element instead of the document object Here’s what this error looks like in the browser’s console: How to …
The error “cannot use import statement outside a module” occurs when you use the import statement outside an ES (ECMAScript) module. If you’re using Node.js, you need to set Node’s module system to ES modules – by adding type: “module” to your package.json file. However, …
How to write the shorthand of if/else statements in JavaScript? If you’re looking for the shorthand of if/else in JavaScript, you need to use the ternary – a.k.a the conditional – operator. The ternary operator takes three operands: a condition followed by a question mark (?), and …
What are those double not operators in JavaScript? You might have noticed a double exclamation mark (!!) in JavaScript code and you may be curious what that means. First, “double exclamation mark” (a.k.a the “double bang”) isn’t an operator itself. It’s two logical not (!) operators …
How would you get the day of the week in JavaScript? If you need to get the day of the week in JavaScript, you can do so with the standard Date object methods – without using a third-party library. The Date object can give us …
How do you subtract days from a date in JavaScript? To subtract a few days from a date in JavaScript, you need to use setDate() on a Date object and decrement the current day of the month – returned by getDate() – by one or more days. You can …
How do you add days to a date in JavaScript? To add a few days to a date in JavaScript, you need to use setDate() on the Date object and increment the current day of the month by one or more days. You can do it in …