Last answered:

30 Jan 2023

Posted on:

29 Jan 2023

2

Resolved: curdate() instead of sysdate()

Is there a difference between using curdate() and sysdate()?

use employees;

DELIMITER $$

CREATE TRIGGER hire_date_check
BEFORE INSERT ON employees
FOR EACH ROW
BEGIN
IF NEW.hire_date > curdate() THEN
SET NEW.hire_date = curdate();
END IF;
END $$

DELIMITER ;

2 answers ( 2 marked as helpful)
Posted on:

29 Jan 2023

1

Hi Vladimir!

Sys date refers to the current date on the SERVERwhere the database is located but curdate() refers to the current date on your ownCLIENT. In this context there is no difference to which one you use.
Hope this helps!
Regards,
Mohaned

Instructor
Posted on:

30 Jan 2023

1

Hi Vladimir and Mohaned!
Thanks for reaching out.

@: Mohaned
Thanks for sharing this piece of information with the Community!

@: Vladimir
The CURDATE() function returns the time stamp of the client while the SYSDATE() function returns the time stamp of the server. If both server and the client are on the same machine, then, the result of both commands are the same. But in case that your sever is for example in USA and your clients are in China, then, these two functions return completely different results.

Hope this helps.
Best,
Tsvetelin

Submit an answer