Re: Passing DateDiff rather than Actual Dates as Parameters



Lauren,
I'll repeat the advice I gave you a couple of days ago in
comp.databases.ms-access
------------------------------------
The easiest way to handle passing dates to SQL Server is to pass it in one
of the formats which Convert understands, then immediately convert it to a
datetime variable.

So for instance you could pass a date in international format.

Format(Date, "YYYYMMDD")

and then in your SP

Create Procedure usp_some_proc
@indate varchar(10)
AS
Declare @real_date datetime

Select @real_date = Convert(datetime, @indate, 112)
-- Then you can just work with @real_date and not worry about the format
------------------------------------

--
Terry Kreft



"laurenq uantrell" <laurenquantrell@xxxxxxxxxxx> wrote in message
news:1133235163.909101.251260@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> I've gotten sort of fed up with dealing with regional date settings on
> the client side and am considering the following scheme - just
> wondering if anyone has a negative view of it or not:
>
> Instead of
>
> @StartDate datetime,
> @EndDate datetime
>
> Use:
>
> @StartDaysDiff int,
> @EndDaysDiff int
>
>
> In the front end app take the desired date and do a DATEDIFF with the
> current date, then pass the date diff as a parameter as an integer
> rather than deal with the dates at all.
>
> Then...
>
> DECLARE @TodayDate datetime, @StartDate datetime, @EndDate datetime
>
> SELECT @TodayDate = GETDATE()
> SELECT @StartDate = DATEDIFF(DAY,@StartDaysDiff,@TodayDate)
> SELECT @EndDate = DATEDIFF(DAY,@EndDaysDiff,@TodayDate)
>
> SELECT
> a.Something
> FROM
> dbo.Appointments a
> WHERE
> a.AppointmentDate BETWEEN @StartDate and @EndDate
>
> Just wondering ...
>
> Thanks,
> lq
>


.



Relevant Pages

  • Re: Trouble with Date Formats
    ... date in string format if you are trying to put a literal date into a SQL ... Function NumMonths(varDate As Variant) As Long ... Dim EndDate As Variant ... StartDate = Format ...
    (microsoft.public.access.modulesdaovba)
  • start and end dates
    ... Declare @StartDate As DateTime ... Declare @EndDate As DateTime ...
    (microsoft.public.sqlserver.olap)
  • Re: parameterized datetime query
    ... This converts the date to a varchar in the format mm/dd/yyyy, and back to datetime. ... Where column Between @startdate and @enddate, where you would build startdate and enddate in your C# code to be the desired date at 00:00:00 and the desired date at 23:59:59, respectively. ... DateTime dateWithoutTime = dateToSearch.Date; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: using NETWORKDAYS
    ... No, but here's a workaround: ... Put startdate in A1 enddate in B1, and list of days you want to ignore ... date format). ...
    (microsoft.public.excel.misc)
  • Using variable in Stored procedure - help!
    ... I am a newbie to this, so I would appreciate any help, I am struggling ... @startdate as datetime ... declare @startdate as datetime ... declare @enddate as datetime ...
    (comp.databases.ms-sqlserver)