Notice (8): file_put_contents(): Write of 270 bytes failed with errno=28 No space left on device [CORE/src/Log/Engine/FileLog.php, line 140]

Notice: file_put_contents() [function.file-put-contents]: Write of 1108 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): unserialize() [<a href='https://secure.php.net/function.unserialize'>function.unserialize</a>]: Error at offset 16363 of 16373 bytes [APP/Controller/NewsController.php, line 5571]

Notice: file_put_contents() [function.file-put-contents]: Write of 2759 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Undefined array key "nsort" [APP/Controller/NewsController.php, line 3613]

Notice: file_put_contents() [function.file-put-contents]: Write of 2073 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Trying to access array offset on value of type null [APP/Controller/NewsController.php, line 3613]

Notice: file_put_contents() [function.file-put-contents]: Write of 2097 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Undefined array key "nsort" [APP/Controller/NewsController.php, line 3613]

Notice: file_put_contents() [function.file-put-contents]: Write of 2073 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Trying to access array offset on value of type null [APP/Controller/NewsController.php, line 3613]

Notice: file_put_contents() [function.file-put-contents]: Write of 2097 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): SplFileObject::fwrite() [<a href='https://secure.php.net/splfileobject.fwrite'>splfileobject.fwrite</a>]: Write of 100 bytes failed with errno=28 No space left on device [CORE/src/Cache/Engine/FileEngine.php, line 141]

Notice: file_put_contents() [function.file-put-contents]: Write of 2790 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (512): long cache was unable to write 'ca1e5a986579b26e31f40ca4ae18ed06' to Cake\Cache\Engine\FileEngine cache [CORE/src/Cache/Cache.php, line 275]

Notice: file_put_contents() [function.file-put-contents]: Write of 2585 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): SplFileObject::fwrite() [<a href='https://secure.php.net/splfileobject.fwrite'>splfileobject.fwrite</a>]: Write of 129 bytes failed with errno=28 No space left on device [CORE/src/Cache/Engine/FileEngine.php, line 141]

Notice: file_put_contents() [function.file-put-contents]: Write of 2790 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (512): long cache was unable to write '96ece811a63b56d7fda79f62c912e71a' to Cake\Cache\Engine\FileEngine cache [CORE/src/Cache/Cache.php, line 275]

Notice: file_put_contents() [function.file-put-contents]: Write of 2585 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): unserialize() [<a href='https://secure.php.net/function.unserialize'>function.unserialize</a>]: Error at offset 4067 of 4085 bytes [APP/Controller/NewsController.php, line 5571]

Notice: file_put_contents() [function.file-put-contents]: Write of 2487 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
SQL年龄计算的两种方法实例 - 站长搜索
首页 > 资讯列表 > 编程/数据库 >>

SQL年龄计算的两种方法实例

Warning (2): Undefined array key "nsort" [ROOT/plugins/Kuhuang/templates/Websites/view.php, line 430]
Notice: file_put_contents() [function.file-put-contents]: Write of 2421 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Trying to access array offset on value of type null [ROOT/plugins/Kuhuang/templates/Websites/view.php, line 430]

Notice: file_put_contents() [function.file-put-contents]: Write of 2445 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
">
Warning (2): Undefined array key "nsort" [ROOT/plugins/Kuhuang/templates/Websites/view.php, line 430]

Notice: file_put_contents() [function.file-put-contents]: Write of 2421 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Warning (2): Trying to access array offset on value of type null [ROOT/plugins/Kuhuang/templates/Websites/view.php, line 430]

Notice: file_put_contents() [function.file-put-contents]: Write of 2445 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
2022-09-23 18:19:35 转载来源: 网络整理/侵权必删

目录第一种方法:第二种方法:总结第一种方法:用DATEDIFF函数,DATEDIFF(YEAR,beginDate,endDate)。测试语句:DECLARE@birthdayDateDATEDECLARE@endDateDATEDECLARE@ageINTSET@birthdayDate='2003-08-08'SET@endDate='2008-07-08'SET@age=DATEDIFF(YEAR,@birthdayDate,@endDate)SELECT@ageAS年龄执行结果:这种方法计算出的年龄,是个大概年龄,是“年”意义下的年龄,就是普罗大众对年龄的理解下的年龄

第一种方法:

用DATEDIFF函数,DATEDIFF(YEAR,beginDate,endDate)

测试语句:

DECLARE @birthdayDate DATEDECLARE @endDate DATEDECLARE @age INTSET @birthdayDate ='2003-08-08'SET @endDate = '2008-07-08'SET @age = DATEDIFF(YEAR,@birthdayDate,@endDate)SELECT @age AS 年龄

执行结果:

这种方法计算出的年龄,是个大概年龄,是“年”意义下的年龄,就是普罗大众对年龄的理解下的年龄。

如果按“月”、“日”去计算,上述例子中的年龄其实是不足5岁的。

所以,当我们写的程序对年龄的计算的精度要求比较高时,

比如社保待遇的享受起始时间、退休金发放起始时间的计算,需要对年龄的精确计算;

政治生活中,干部的提拔、退职,也都涉及到年龄的精确计算;

民事刑事案件中当事人年龄的计算,年龄的大小直接涉及到量刑的轻重,所以也需要对年龄进行精确计算。

第二种方法:

FLOOR(DATEDIFF(DAY,@birthdayDate,@endDate)/365.25)

FLOOR函数:返回小于或等于指定数值表达式的最大整数。又称,向下取整函数。

(Returns the largest integer less than or equal to the specified numeric expression.)

PS:numberic expression,数值表达式 ,arithmeric expression,算术表达式。

FLOOR(4)=4,

FLOOR(4.2)=4,

FLOOR(4.5)=4,

FLOOR(4.9)=4.

测试语句:

DECLARE @birthdayDate DATEDECLARE @endDate DATEDECLARE @age FLOATSET @birthdayDate ='2003-08-08'SET @endDate = '2008-07-08'SET @age = FLOOR(DATEDIFF(DAY,@birthdayDate,@endDate)/365.25)SELECT @age AS 年龄

执行结果:

算法释义:

因为4年有一闰年会多1天,多除以0.25,相当于把这一天平均摊到这4年,保证每4年的误差归零。

这个算法其实也有小小的误差,除非出生不满一岁就碰到闰月,先有一天再来递减,会完全正确,不然的话在遇到闰年前会差一天,遇到闰年后变准确,但是当这个闰年补完4年差额在遇到下一个闰年之前又会差一天。也就是生日当天程序会显示没满周岁。

我们测试一下,比如2000、2004、2008年是闰年,但是2001、2002、2003、2005、2006、2007年都不是闰年。

假定李某在2001-02-08出生,我们用2002、2003、2004年生日当天去计算年龄时,都会发生误差。

因为2004年是闰年,用2005年生日当天去计算年龄就正确,过了2005年(2005-2001=4),我们用2006、2007、2008年生日当天去计算年龄,也会发生误差。

如果李某在2001-03-08(只要过了2月的一个日期就行)出生,

我们用2002、2003年生日当天去计算年龄时,会发生误差。

但是用2004、2005年生日当天去计算年龄就正确,过了2005年(2005-2001=4),我们用2006、2007年生日当天去计算年龄,也会发生误差。

用2008年生日当天去计算年龄,就没有误差。

请读者自行验证。

总结

到此这篇关于SQL年龄计算的文章就介绍到这了,更多相关SQL年龄计算内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

标签: SQL 年龄 计算 两种 方法 实例


声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!

站长搜索

http://www.adminso.com

Copyright @ 2007~2025 All Rights Reserved.

Powered By 站长搜索

打开手机扫描上面的二维码打开手机版


使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

站长搜索目录系统技术支持