Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1347494
  • 博文数量: 205
  • 博客积分: 6732
  • 博客等级: 准将
  • 技术积分: 2835
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-04 17:59
文章分类

全部博文(205)

文章存档

2016年(1)

2015年(10)

2014年(1)

2013年(39)

2012年(23)

2011年(27)

2010年(21)

2009年(55)

2008年(28)

我的朋友

分类: DB2/Informix

2013-05-24 14:27:46


点击(此处)折叠或打开

  1. --获取当前日期:


  2. select current date from sysibm.sysdummy1;
  3. values current date;

  4. --获取当前日期

  5. select current time from sysibm.sysdummy1;
  6. values current time;
  7. --获取当前时间戳

  8. select current timestamp from sysibm.sysdummy1;
  9. values current timestamp;

  10. --要使当前时间或当前时间戳记调整到 GMT/CUT,则把当前的时间或时间戳记减去当前时区寄存器:


  11. values current time -current timezone;
  12. values current timestamp -current timezone;

  13. --获取当前年份


  14. values year(current timestamp);

  15. --获取当前月

  16. values month(current timestamp);

  17. --获取当前日

  18. values day(current timestamp);

  19. --获取当前时

  20. values hour(current timestamp);

  21. --获取分钟

  22. values minute(current timestamp);

  23. --获取秒

  24. values second(current timestamp);

  25. --获取毫秒

  26. values microsecond(current timestamp);

  27. --从时间戳记单独抽取出日期和时间


  28. values date(current timestamp);
  29. values VARCHAR_FORMAT(current TIMESTAMP,'yyyy-mm-dd');
  30. values char(current date);
  31. values time(current timestamp);

  32. --执行日期和时间的计算


  33. values current date+1 year;
  34. values current date+3 years+2 months +15 days;
  35. values current time +5 hours -3 minutes +10 seconds;

  36. --计算两个日期之间的天数


  37. values days(current date)- days(date('2010-02-20'));

  38. --时间和日期换成字符串


  39. values char(current date);
  40. values char(current time);

  41. --要将字符串转换成日期或时间值


  42. values timestamp('2010-03-09-22.43.00.000000');
  43. values timestamp('2010-03-09 22:44:36');
  44. values date('2010-03-09');
  45. values date('03/09/2010');
  46. values time('22:45:27');
  47. values time('22.45.27');

  48. --计算两个时间戳记之间的时差:


  49. --秒的小数部分为单位

  50. values timestampdiff(1,char(current timestamp - timestamp('2010-01-01-00.00.00')));
  51. --秒为单位

  52. values timestampdiff(2,char(current timestamp - timestamp('2010-01-01-00.00.00')));
  53. --分为单位

  54. values timestampdiff(4,char(current timestamp - timestamp('2010-01-01-00.00.00')));
  55. --小时为单位

  56. values timestampdiff(8,char(current timestamp - timestamp('2010-01-01-00.00.00')));
  57. --天为单位

  58. values timestampdiff(16,char(current timestamp - timestamp('2010-01-01-00.00.00')));
  59. --周为单位

  60. values timestampdiff(32,char(current timestamp - timestamp('2010-01-01-00.00.00')));
  61. --月为单位

  62. values timestampdiff(64,char(current timestamp - timestamp('2010-01-01-00.00.00')));
  63. --季度为单位

  64. values timestampdiff(128,char(current timestamp - timestamp('2010-01-01-00.00.00')));
  65. --年为单位

  66. values timestampdiff(256,char(current timestamp - timestamp('2010-01-01-00.00.00')));

 

阅读(649) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~