MySQL 如何从服务器获取当前日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18008873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to get current date from server
提问by Subodh
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
我想从服务器获取当前日期,我的数据库在服务器上,那么无论是客户端机器还是服务器,mysql now() 和 CURDATE() 函数都会给出其日期。请帮忙。这就是我所做的
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());
采纳答案by RandomSeed
Both functions are executed by MySQL. So they return the date and time of the system running the MySQL process.
这两个函数都由 MySQL 执行。因此它们返回运行 MySQL 进程的系统的日期和时间。
回答by MohsenB
There are 8 ways to get the current time:
有8种方法可以获取当前时间:
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
回答by The Ray of Hope
replace now() to CURDATE() function ...I also use that code
将 now() 替换为 CURDATE() 函数...我也使用该代码