Java SQL Timestamp before() function with examples Last Updated : 06 Mar, 2019 Comments Improve Suggest changes Like Article Like Report The before() function is a part of Timestamp class of Java SQL.The function returns a boolean value representing whether the Timestamp object occurs before the given Timestamp object. Function Signature: public boolean before(Timestamp t) Syntax: ts1.before(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 before the given Timestamp object. Exception: The function does not throw any exceptions Below examples illustrate the use of before() function Example 1: Create two non equal timestamps and check whether the second timestamp occurs before first timestamp or not. Java // Java program to demonstrate the // use of before() function import java.sql.*; public class solution { public static void main(String args[]) { // Create two timestamp objects Timestamp ts1 = new Timestamp(10003); Timestamp ts2 = new Timestamp(10001); boolean b = ts2.before(ts1); // Check if the second timestamp occurs // before first timestamp if (b) { // If true print that the Second Timestamp // occurs before the first timestamp System.out.println("Second Timestamp occurs" + " before first timestamp"); } else { // If false print that the Second Timestamp // does not occur before the first timestamp System.out.println("Second Timestamp does not occur" + " before first timestamp"); } } } Output: Second Timestamp occurs before first timestamp Example 2: Create two equal timestamps and check whether the second timestamp occurs before the first timestamp or not Java // Java program to demonstrate the // use of before() 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.before(ts1); // Check if the second timestamp occurs // before first timestamp if (b) { // If true print that the Second Timestamp // occurs before the first timestamp System.out.println("Second Timestamp occurs" + " before first timestamp"); } else { // If false print that the Second Timestamp // does not occur before the first timestamp System.out.println("Second Timestamp does not" + " occur before first timestamp"); } } } Output: Second Timestamp does not occur before first timestamp Reference: https:// docs.oracle.com/javase/7/docs/api/java/sql/Timestamp.html Comment More infoAdvertise with us A andrew1234 Follow Improve Article Tags : Java Java-Functions Java-Sql package Java-TimeStamp Explore Java BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOP & InterfacesClasses and Objects in Java10 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java10 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial15+ min readJava Networking15+ min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like