Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get current date from server

i want to get the current date from server and my database is on server then whose date mysql now() and CURDATE() function will give, whether of client machine or of server. Please help. this is what i'hv done

insert into admission_fees_structure (Fee_Head_Name , Amount,Created_Date , Created_By) values (feeName, amount, now(),userID);
select name into @result from sims.school_session where YEAR(Start_Date)=YEAR(CURDATE());
like image 336
Sudarshan Avatar asked Aug 02 '13 04:08

Sudarshan


People also ask

How do I get the current date in SQL Server?

SQL Server GETDATE() Function The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss. mmm' format. Tip: Also look at the CURRENT_TIMESTAMP function.

How can I get current date in database?

INSERT INTO yourTableName(yourDateColumnName) VALUES(NOW()); If your column has datatype date then NOW() function inserts only current date, not time and MySQL will give a warning. To remove the warning, you can use CURDATE().

How do I get the current date in SQL Server without time?

We'll use the GETDATE() function to get the current date and time. Then we'll use the CAST() function to convert the returned datetime data type into a date data type.

How do I use Sysdate 1 in SQL Server?

MySQL SYSDATE() Function The SYSDATE() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH:MM:SS" (string) or as YYYYMMDDHHMMSS (numeric).


2 Answers

There are 8 ways to get the current time:

SELECT NOW() FROM DUAL;
   2006-07-01 10:02:41 

SELECT CURRENT_TIME() FROM DUAL;
   10:02:58

SELECT SYSDATE() FROM DUAL;
   2006-07-01 10:03:21 

mysql> SELECT CURRENT_TIMESTAMP() FROM DUAL;
   2006-07-01 10:04:03 

SELECT LOCALTIME() FROM DUAL;
   2006-07-01 10:07:37 

mysql> SELECT LOCALTIMESTAMP() FROM DUAL;
   2006-07-01 10:08:08 

mysql> SELECT UTC_TIME() FROM DUAL;
   14:09:22 

mysql> SELECT UTC_TIMESTAMP() FROM DUAL;
   2006-07-01 14:09:49 
like image 68
MohsenB Avatar answered Oct 17 '22 05:10

MohsenB


Both functions are executed by MySQL. So they return the date and time of the system running the MySQL process.

like image 38
RandomSeed Avatar answered Oct 17 '22 06:10

RandomSeed