Date and Time Math in Python

Rajendra Dharmkar
Updated on 02-Nov-2023 02:07:05

4K+ Views

It is very easy to do date and time maths in Python using timedelta objects. Whenever you want to add or subtract to a date/time, use a datetime.datetime(), then add or subtract datetime.timedelta() instances. A timedelta object represents a duration, the difference between two dates or times. The timedelta constructor has the following function signature −datetime.timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]])Note: All arguments are optional and default to 0. Arguments may be ints, longs, or floats, and may be positive or negative. You can read more about it here − https://docs.python.org/2/library/datetime.html#timedelta-objectsExampleAn example of using the timedelta objects and dates ... Read More

Set First Day of Each Week to Weekday using Python

Vikram Chiluka
Updated on 02-Nov-2023 01:55:00

4K+ Views

In this article, we will show you how to set the first day of each week to a weekday using Python. Now we see 2 methods to accomplish this task− Using setfirstweekday() function Using setfirstweekday() function to set a given weekday Number Method 1: Using setfirstweekday() function to set given weekDay Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task − Use the import keyword, to import the calendar module. Use the prmonth() function (It is used to print the calendar for a month) of the calendar module to print the calendar ... Read More

Sort a Python Date String List

Vikram Chiluka
Updated on 02-Nov-2023 01:52:09

40K+ Views

In this article, we will show you how to sort a Python date string list. Now we see 3 methods to accomplish this task− Now we see 2 methods to accomplish this task− Using sort() and lambda functions Using sort() function Using sorted function Method 1: Using sort() and lambda functions Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task − Use the import keyword, to import the datetime from datetime module (To work with dates and times, Python has a module called datetime). Create a variable to store the input list ... Read More

Convert Python Date to JSON Format

Rajendra Dharmkar
Updated on 02-Nov-2023 01:50:21

3K+ Views

There is no standard JSON format for dates. Although JavaScript does have a standard date format that is human readable, sorts correctly, includes fractional seconds(which can help re-establish chronology) and  conforms to ISO 8601. You can convert a Python date to the JS date format using the strftime function and deserialize it using the client that needs this date. To get an ISO 8601 date in string format in Python 3, you can simply use the isoformat function. It returns the date in the ISO 8601 format. For example, if you give it the date 31/12/2017, it'll give you the ... Read More

Configure Nginx as Reverse Proxy for WebSocket

Sharon Christine
Updated on 02-Nov-2023 00:49:03

43K+ Views

The WebSocket is a protocol which provides a way of creating web applications that supports real-time bi-directional communication between both clients and servers. WebSocket makes it much easier to develop these types of applications. Most modern browsers support WebSocket including Firefox, Internet Explorer, Chrome, Safari, and Opera, and more and more server application frameworks are now supporting WebSocket as well.For a production environment, where multiple WebSocket servers are needed for getting a good performance and high availability of the website or application, a load balancing layer which understands the WebSocket protocol is required, NGINX supports the use of WebSocket from ... Read More

Difference Between Inverting and Non-Inverting Amplifier

Manish Kumar Saini
Updated on 02-Nov-2023 00:38:40

49K+ Views

In electronic circuits, we use an electronic device called operational amplifier (Op-Amp). The operational amplifier is a high-gain multistage differential amplifier. It has two inputs and one output, where the input terminals are named as inverting terminal and non-inverting terminal. The inverting terminal of the Op-Amp is marked with positive (+) polarity, whereas the noninverting represents the negative (-) polarity terminal. Depending on the circuit configuration, the operational amplifier is classified into two types namely, Inverting Amplifier Non-Inverting Amplifier This article is meant for explaining the differences between an inverting amplifier and a noninverting amplifier. But before that, ... Read More

Bipolar Junction Transistor (BJT) Theory

Manish Kumar Saini
Updated on 02-Nov-2023 00:27:28

42K+ Views

A Bipolar Junction Transistor (BJT) is a three-terminal device which consists of two pn-junctions formed by sandwiching either p-type or n-type semiconductor material between a pair of opposite type semiconductors.The primary function of BJT is to increase the strength of a weak signal, i.e., it acts as an amplifier. A BJT can also be used as a solid state switch in electronic circuits.Types of BJTThere are two types of BJTs −NPN TransistorPNP TransistorIn this article, we will discuss in detail the working principle of both these types of BJTs.NPN TransistorAn npn-transistor is composed of two n-type semiconductor materials which are ... Read More

Introduction to Backtracking

sudhir sharma
Updated on 02-Nov-2023 00:22:40

27K+ Views

Backtracking is a technique based on algorithm to solve problem. It uses recursive calling to find the solution by building a solution step by step increasing values with time. It removes the solutions that doesn't give rise to the solution of the problem based on the constraints given to solve the problem.Backtracking algorithm is applied to some specific types of problems, Decision problem used to find a feasible solution of the problem.Optimisation problem used to find the best solution that can be applied.Enumeration problem used to find the set of all feasible solutions of the problem.In backtracking problem, the algorithm ... Read More

Add Country Area Code to Phone Number List in Excel

Pradeep Kumar
Updated on 01-Nov-2023 20:21:50

49K+ Views

In this tutorial, you will learn how to format phone numbers with country code using three simple methods. Method 1: Using Format for Phone Number with Country Code You need to take the following actions to be able to add a country code to the Formatted Number column. Step 1 Select the phone number from the range of cells C1:C7. Step 2 Press ctrl+1. When Format cells dialog box opens, choose Custom and type +1 (000) 000-0000, then click OK. Result Finally, the outcome with country codes in the Formatted Number cells are shown in ... Read More

Get System Uptime with PowerShell

Chirag Nagrekar
Updated on 01-Nov-2023 20:16:48

49K+ Views

To get the Windows System uptime with PowerShell, we can use the CIM Instance method with class name Win32_OperatingSystem. Once you use the mentioned class there is a property called LastBootupTime which shows the date when the computer is last rebooted.ExampleGet-CimInstance -ClassName Win32_OperatingSystem | Select LastBootUpTimeOutputLastBootUpTime -------------- 9/29/2020 8:12:08 AMIf we check the datatype of the above output, it should be DateTime because of the output format.(Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime.Gettype()OutputIsPublic IsSerial Name     BaseType -------- -------- ----     -------- True     True     DateTime System.ValueTypeWe need now the uptime of the system in Days-Hours-Minutes format. So we will compare ... Read More

Advertisements