Comparison of Dates in PHP

Alok Prasad
Updated on 30-Jul-2019 22:30:26

7K+ Views

Matching two dates in PHP is quite smooth when both the dates are in a similar format but php failed to analyze when the two dates are in an unrelated format. In this article, we will discuss different cases of date comparison in PHP. We will figure out how to utilize DateTime class, strtotime() in comparing dates.Case 1:we can analyze the dates by simple comparison operator if the given dates are in a similar format.Output:2019-03-26 is latest than 2018-11-24Explanation:Here we have declared two dates $date1 and $date2 in the same format. So we have used a comparison operator(>) to compare ... Read More

Use ObjectId Under findOne to Fetch a Specific Record in MongoDB

Anvi Jain
Updated on 30-Jul-2019 22:30:26

479 Views

Let us first create a collection with documents −> db.findOneWorkingDemo.insertOne({"ClientId":1, "ClientName":"Larry", "ClientAge":26}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7c1716d78f205348bc64d") } > db.findOneWorkingDemo.insertOne({"ClientId":2, "ClientName":"Chris", "ClientAge":28}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7c17d6d78f205348bc64e") } > db.findOneWorkingDemo.insertOne({"ClientId":3, "ClientName":"Robert", "ClientAge":34}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7c1896d78f205348bc64f") }Following is the query to display all documents from a collection with the help of find() method −> db.findOneWorkingDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd7c1716d78f205348bc64d"),    "ClientId" : 1,    "ClientName" : "Larry",    "ClientAge" : 26 } {    "_id" : ObjectId("5cd7c17d6d78f205348bc64e"),    "ClientId" : 2, ... Read More

Using Iterations in Python Effectively

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

240 Views

In this article, we will learn about how to implement iterators and their effective implementation in Python 3.x. Or earlier. Let’ s take a look at various methods available in python which implements iterators.Type 1 − Implementation Of While Loop With Known LengthExample Code Live Demogenre = ("Python", "C", "C++", "Java") print("The topic available on Tutorial's Point are:") i = 0 while (i < len(genre)): print (genre[i]) i += 1ExplanationDue to its less compact structure, this method is not favored. Error Handling is also difficult in this case . Large-scale programs or designs doesn’t use ... Read More

Create New Value from Int Array in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:26

574 Views

Let’s say the following is our int array elements:10, 50, 100, 200, 250, 300, 400, 500Here, we are mapping and creating a new value by incrementing each int element with 1:Arrays.stream(new int[] {10, 50, 100, 200, 250, 300, 400, 500}).map(val -> val + 1)Now find the average:Arrays.stream(new int[] {10, 50, 100, 200, 250, 300, 400, 500}).map(val -> val + 1).average()The following is an example to Map and create new value from int array:Exampleimport java.util.Arrays; public class Demo {    public static void main(String[] args) throws Exception {       Arrays.stream(new int[] {10, 50, 100, 200, 250, 300, 400, 500}).map(val -> val + 1).average()          .ifPresent(System.out::println);    } }Output227.25

Difference Between const int, const int&, and int const

Smita Kapse
Updated on 30-Jul-2019 22:30:26

563 Views

Here we will see some different types of variable declaration based on integer pointers integer constants and the integer constant pointers.To determine them we will use the Clockwise/Spiral Rule. By discussing the terms, we can understand the rules also.The const int *. This is used to tell the compiler that this is a pointer type variable, and this can store address of some constant int. The Clock rule is saying like this −Now the another one is const int * const. This is used to denote that this is one constant pointer variable, which can store the address of another ... Read More

Query for Multiple Parameters in MongoDB

Anvi Jain
Updated on 30-Jul-2019 22:30:26

2K+ Views

To query for multiple parameters in MongoDB, you can use the dot(.) notation. Let us first create a collection with documents −> db.multipleParametersDemo.insertOne( ...    { ...       "CustomerName" : "Larry", ...       "CustomerDetails" : [ ...          { ...             "CustomerCountryName" : "US", ...             "CustomerBankName" : "HDFC", ...             "CustomerBalance" : 17363, ...          } ...       ], ...       "Purchase" : 1456, ... ...    } ... ); ... Read More

Set Background Color of a Single Tab in JTabbedPane with Java

Anvi Jain
Updated on 30-Jul-2019 22:30:26

1K+ Views

To set the background color of a single tab, use the setBackgroundAt() method. This gives an option to mention the index and the color. The index here is the index of the specific tab you want to color.Let us first create a JTabbedPane −JTabbedPane tabbedPane = new JTabbedPane();Now, set the background color for one of the tabs with index 2 −tabbedPane.setBackgroundAt(2, Color.RED);The following is an example to set the background color of a single tab in a JTabbedPane container −Examplepackage my; import javax.swing.*; import java.awt.*; public class SwingDemo {    public static void main(String args[]) {       JFrame ... Read More

MySQL Order By with Mixed Ordering

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

178 Views

You can use the field() for this. Let us first create a table −mysql> create table DemoTable    (    Value int    ); Query OK, 0 rows affected (0.80 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(70); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(60); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(56); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(81); Query OK, 1 row affected (0.44 sec) mysql> ... Read More

Difference Between Pointer and Reference Parameter in C++

Anvi Jain
Updated on 30-Jul-2019 22:30:26

6K+ Views

PointersPointer variables are used to store the address of variable.SyntaxType *pointer;InitializationType *pointer; Pointer=variable name;ReferencesWhen a parameter is declared as reference, it becomes an alternative name for an existing parameter.SyntaxType &newname=existing name;InitializationType &pointer; Pointer=variable name;The main differences between pointers and reference parameters are −References are used to refer an existing variable in another name whereas pointers are used to store address of variable.References cannot have a null value assigned but pointer can.A reference variable can be referenced by pass by value whereas a pointer can be referenced by pass by reference.A reference must be initialized on declaration while it is not ... Read More

C++ Program to Shutdown a System

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

789 Views

Here we will see how we can shut down the system by writing a simple C or C++ code. The shutdown process varies in different OS. If we are Linux user, we can use this terminal command to shut down.shutdown –P nowIf we are using Windows system, we can use this command −c:\windows\system32\shutdown /iWe will see the code for Linux and WindowsExample(Linux)#include using namespace std; int main() {    system("shutdown -P now"); }Example(Windows)#include using namespace std; int main() {    system("c:\windows\system32\shutdown /i "); }

Advertisements