获取SQL的日期

时间:2014-06-03 18:33:34

标签: mysql reporting

我有一张桌子,我希望得到年份的月份和日期。所以基本上我想要这个 ' 2010-06-08'并且不希望这个' 2010-06-08 11:03:25.797'该表给了我第二个选项,但我只想得到年月和日。 Heres是我的编解码器,它是一个存储过程。

    ALTER PROC [dbo].[spAdminCancelRefundDate]

    (@Beginning_Date  DATE, 
     @Ending_Date DATE,
     @program int=null)

As
Begin

  SELECT  @program, c.program_id, d.dealer_code,b.last_name As DealerName, a.account_no, a.vin,  ((e.last_name)+','+(e.first_name)) As Name, 
  a.cancel_refund_date, a.purchase_date,a.miles, a.duration,a.sale_price,a.number_of_payments,  a.sales_tax, a.downpayment

from tDealer d 
    Join tContact b ON d.contact_id = b.contact_id 
    Join tContract a On d.dealer_id = a.dealer_id 
    Join tCompany c ON d.company_id= c.company_id
    Join tContact E On e.contact_id = a.contact_id

    Where c.program_id = @program And a.cancel_refund_date between @Beginning_Date and @Ending_Date
End 

2 个答案:

答案 0 :(得分:0)

在mysql中使用date函数。您可以看到官方网站here

mysql> SELECT DATE('2003-12-31 01:02:03');
        -> '2003-12-31'

或者如果你想格式化那个日期,请考虑这个,

mysql> SELECT DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y');
        -> 'Sunday October 2009'
mysql> SELECT DATE_FORMAT('2007-10-04 22:23:00', '%H:%i:%s');
        -> '22:23:00'
mysql> SELECT DATE_FORMAT('1900-10-04 22:23:00',
    ->                 '%D %y %a %d %m %b %j');
        -> '4th 00 Thu 04 10 Oct 277'
mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00',
    ->                 '%H %k %I %r %T %S %w');
        -> '22 22 10 10:23:00 PM 22:23:00 00 6'
mysql> SELECT DATE_FORMAT('1999-01-01', '%X %V');
        -> '1998 52'
mysql> SELECT DATE_FORMAT('2006-06-00', '%d');
        -> '00'

答案 1 :(得分:0)

只需在DATE()对象上使用DATETIME调用,就会返回它的日期部分。例如:

mysql> SELECT DATE('2003-12-31 01:02:03');
-> '2003-12-31'

Here是更多MYSQL DateTime函数的文档。