日期格式问题

时间:2012-08-28 09:22:54

标签: sql-server-2005 datetime-format

SQL Server 2005中的一个问题:

我需要dd/mm/yyyy格式的所有日期

SELECT
    CONVERT(NCHAR(10), FromDate, 103) AS FromDate,
    CONVERT(NCHAR(10), ToDate, 103) AS ToDate 
FROM Tbl_PropertyRoomSeasonPrices

输出:

28/08/2012  |   09/01/2012

dd/mm/yyyy  |   mm/dd/yyyy  
(CORRECT)       (WRONG)

但fromDate为103,toDate为101,两者相同,为什么会有变化?

值保存如下:

BLL

public DateTime FromDate
    {
        get {return _fromDate;} 
        set{ _fromDate = value; }
    }

    public DateTime ToDate
    {
        get {return _toDate;}   
        set{ _toDate = value;   }
    }

 public bool Save()
    {
        return _dalTbl_PropertyRoomSeasonPrices.Save();
    }

DAL

public bool Save()
    {
        try
{
 DataAccessLayerBaseClassDALBC=DataAccessLayerFactory.GetDataAccessLayer();         
 IDataParameter[]parameters=DALBC.CreateParameters(2);
 parameters[0] = DALBC.CreateParameter("@FromDate",    this._tbl_propertyroomseasonprices.FromDate);
parameters[1] = DALBC.CreateParameter("@ToDate",    this._tbl_propertyroomseasonprices.ToDate);
DALBC.ExecuteScalar("spSave_Tbl_PropertyRoomSeasonPrices", CommandType.StoredProcedure, parameters);                
        }
        catch (Exception ex)
        {

            return false;
        }
        return true;
    }

SQL

ALTER PROCEDURE [dbo].[spSave_Tbl_PropertyRoomSeasonPrices]
(
@Id int,

@FromDate datetime = NULL,
@ToDate datetime = NULL

)
AS
DECLARE @count int  
SET NOCOUNT ON

SELECT @count=COUNT(*) FROM Tbl_PropertyRoomSeasonPrices WHERE 
        [Id] = @Id

IF @count<=0 BEGIN
    INSERT INTO [Tbl_PropertyRoomSeasonPrices]
    (

    [FromDate],
    [ToDate]
    )
    VALUES
    (   

    @FromDate,
    @ToDate     
    )

SELECT @Id = SCOPE_IDENTITY();


END
ELSE BEGIN
    UPDATE [Tbl_PropertyRoomSeasonPrices]
    SET

    [FromDate] = @FromDate,
    [ToDate] = @ToDate

    WHERE 
            [Id] = @Id


END 


        SELECT @Id

0 个答案:

没有答案