Thursday, March 12, 2026
HomeLanguagesJavaJava SQL Timestamp after() function with examples

Java SQL Timestamp after() function with examples

The after() function is a part of Timestamp class of Java SQL.The function returns a boolean value representing whether the Timestamp object occurs after the given Timestamp object .

Function Signature:

public boolean after(Timestamp t)

Syntax:

ts1.after(ts2);

Parameters: The function accepts Timestamp object as parameter which is to be checked.

Return value: The function returns boolean data type representing whether the Timestamp object occurs after the given Timestamp object.

Exception: The function does not throw any exceptions

Below examples illustrate the use of after() function

Example 1: Create two non equal timestamps and check whether the second timestamp occurs after first timestamp or not




// Java program to demonstrate the
// use of after() function
  
import java.sql.*;
  
public class solution {
    public static void main(String args[])
    {
  
        // Create two timestamp objects
        Timestamp ts1 = new Timestamp(10000);
        Timestamp ts2 = new Timestamp(10001);
  
        boolean b = ts2.after(ts1);
  
        // Check if the second timestamp occurs
        // after first timestamp
        if (b) {
  
            // If true print that the Second Timestamp
            // occurs after the first timestamp
            System.out.println("Second Timestamp occurs"
                               + " after first timestamp");
        }
  
        else {
  
            // If false print that the Second Timestamp
            // does not occur after the first timestamp
            System.out.println("Second Timestamp does not"
                               + " occur after first timestamp");
        }
    }
}


Output:

Second Timestamp occurs after first timestamp

Example 2: Create two equal timestamps and check whether the second timestamp occurs after first timestamp or not




// Java program to demonstrate the
// use of after() function
  
import java.sql.*;
  
public class solution {
    public static void main(String args[])
    {
  
        // Create two timestamp objects
        Timestamp ts1 = new Timestamp(10000);
        Timestamp ts2 = new Timestamp(10000);
  
        boolean b = ts2.after(ts1);
  
        // Check if the second timestamp occurs
        // after first timestamp
        if (b) {
  
            // If true print that the Second Timestamp
            // occurs after the first timestamp
            System.out.println("Second Timestamp occurs"
                               + " after first timestamp");
        }
        else {
  
            // If false print that the Second Timestamp
            // does not occur after the first timestamp
            System.out.println("Second Timestamp does not"
                               + " occur after first timestamp");
        }
    }
}


Output:

Second Timestamp does not occur after first timestamp

Reference: https:// docs.oracle.com/javase/7/docs/api/java/sql/Timestamp.html

RELATED ARTICLES

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS