不管是在Excel函数中,还是在SQL语句中,亦或是在Python代码中,获取指定日期和进行日期时间的计算都是我们在数据分析中需要频繁使用到的,村长今天就跟大家分享一下如何在Excel、SQL和Python中获取指定日期!
01
获取当前的日期
![bf5fceab1220cc321f66a76d22414e5e.png](https://img-blog.csdnimg.cn/img_convert/bf5fceab1220cc321f66a76d22414e5e.png)
![7b3aec177caa67bc0102531fbe8c9d90.png](https://img-blog.csdnimg.cn/img_convert/7b3aec177caa67bc0102531fbe8c9d90.png)
![54c0d13ea12509ddb141ca60e5a1643c.png](https://img-blog.csdnimg.cn/img_convert/54c0d13ea12509ddb141ca60e5a1643c.png)
Excel函数
=TEXT(TODAY(),"YYYY-MM-DD")
![95f7d31ab4e1ca075589601642eee5e7.png](https://img-blog.csdnimg.cn/img_convert/95f7d31ab4e1ca075589601642eee5e7.png)
在Excel函数中,TODAY函数用于获取当前日期,该函数没有参数,这里用TEXT函数将获取的日期转换成指定格式,返回结果:2020-09-05
![52155da867c6281d85788e2248455447.png](https://img-blog.csdnimg.cn/img_convert/52155da867c6281d85788e2248455447.png)
![52bfc0c8a27cd42b86f6dff644c783ac.png](https://img-blog.csdnimg.cn/img_convert/52bfc0c8a27cd42b86f6dff644c783ac.png)
SQL函数
SELECT TO_CHAR(SYSDATE,'YYYY-MM-DD') FROM DUAL
![de2708c26eaedda2d77fd528a8487a27.png](https://img-blog.csdnimg.cn/img_convert/de2708c26eaedda2d77fd528a8487a27.png)
在Oracle SQL中,SYSDATE函数用于获取当前日期,该函数没有参数也没有括号,这里用TO_CHAR函数将获取的日期转换成指定格式,返回结果:2020-09-05
![c7a189d82ee8de2084d30cd7c95c521b.png](https://img-blog.csdnimg.cn/img_convert/c7a189d82ee8de2084d30cd7c95c521b.png)
![3595619dbf995f18755cd08c1a400a00.png](https://img-blog.csdnimg.cn/img_convert/3595619dbf995f18755cd08c1a400a00.png)
![26fd0a1bf03017830786051e3bc7422c.png](https://img-blog.csdnimg.cn/img_convert/26fd0a1bf03017830786051e3bc7422c.png)
Python代码