473,424 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,424 software developers and data experts.

Date Parameter when using Intl Date Formats

I already figured out (the hard way) I need to convert all my date
parameters into USA format before executing my stored procedures where
dates are used as parameters.
(Format(StartDate, "m/d/yyyy hh:nn:ss AM/PM")

At least I thought I did!

But then I discover that if I use the following construction, the dates
do not need to be formatted to USA first:

Dim StartDate as Date, EndDate as Date

StartDate = Date()
EndDate = Date() +1

cmd.Execute , Parameters:=Array(StartDate, EndDate),
Options:=adExecuteNoRecords

Am I smoking dope here or did our MS friends make this more confusing
than necessary?

Nov 28 '05 #1
11 1877
Lauren Quantrell wrote in message
<11*********************@o13g2000cwo.googlegroups. com> :
I already figured out (the hard way) I need to convert all my date
parameters into USA format before executing my stored procedures where
dates are used as parameters.
(Format(StartDate, "m/d/yyyy hh:nn:ss AM/PM")

At least I thought I did!

But then I discover that if I use the following construction, the dates
do not need to be formatted to USA first:

Dim StartDate as Date, EndDate as Date

StartDate = Date()
EndDate = Date() +1

cmd.Execute , Parameters:=Array(StartDate, EndDate),
Options:=adExecuteNoRecords

Am I smoking dope here or did our MS friends make this more confusing
than necessary?


There's a bit of difference between concatenating some dynamic
sql STRING, where you'll need to spoonfeed it with enough
information to make correct assessement of the passed STRING,
and passing parameters of a specific/specified datatype.

The latter, is perhaps comparable to assigning values between
variables of the same datatype

somedate = somotherdate

Those methods makes it a bit easier to deal with single quotes
for text parametes and other special characters, too.

I'll more often do something like

with cmd
...
.set prm = .createparameter("MyDate", addate, adparaminput)
.parameters.append prm
prm.value = dtMyDate
...

--
Roy-Vidar

Nov 28 '05 #2
Roy,
Yes thanks. The problem seems to come when I store the date value in a
text field. That always has to be converted when refering to the text
fiield in a parameter:

.set prm = .createparameter("MyDate", addate, adparaminput)
.parameters.append prm
.prm.value = (Format(Me.StartDate, "m/d/yyyy hh:nn:ss AM/PM")

And also when using the InputParameters property of a property sheet:

@StartDate = Date()

does not work but:

Format(Date(), "m/d/yyyy hh:nn:ss AM/PM")

does work.

That I find strange!

Nov 28 '05 #3
Lauren Quantrell wrote:

yyyy-mm-dd hh:nn:ss

always works

It has the added advantage of being the accepted notation in the
civilized (civilized=non Anglo) world.

Nov 28 '05 #4
Lauren Quantrell wrote in message
<11**********************@z14g2000cwz.googlegroups .com> :
Roy,
Yes thanks. The problem seems to come when I store the date value in a
text field. That always has to be converted when refering to the text
fiield in a parameter:

.set prm = .createparameter("MyDate", addate, adparaminput)
.parameters.append prm
.prm.value = (Format(Me.StartDate, "m/d/yyyy hh:nn:ss AM/PM")

And also when using the InputParameters property of a property sheet:

@StartDate = Date()

does not work but:

Format(Date(), "m/d/yyyy hh:nn:ss AM/PM")

does work.

That I find strange!


I don't know about the other things, but here

.prm.value = (Format(Me.StartDate, "m/d/yyyy hh:nn:ss AM/PM")

you are effectively doing something like this
- take the contents of (presumably) a text control, which might
be a valid date
- format it to a STRING representation of that date in US date
- this is coerced/cast implicitly back to being a date when
assigned to the parameter

Doing stuff with dates seems to bring a lot of interresting
challenges. What I try to be carefull about, is keeping
dates as dates, and try to avoid formatting dates to strings
and back when assigning. When living in nondefault places,
thats often where the amusement starts;-)

I think I'd validate the contents of the text control, assign
to a date variable, perhaps, or directly to the parameter
without formatting between date and string.

If you wan't to use format, I think you'd need to
disambiguate it, use for instance the one Allen
Browne shows here
http://allenbrowne.com/ser-36.html
"mm\/dd\/yyyy ... or the one Lyle Fairfield presents,
elsethreads, but darned if I know what happens if you
let Access implicitly cast a string representation of an
US date to a variable of datatype date, when the system
on which it is run has it's "belief system" anchored to
UK regional settings, but I think it will create some
hillarius hours of debugging when both the day and
month are less than 13;-)

' try this with UK settings ...

dim dt1 as date
dim dt2 as date
dim dt3 as date
dt1 = #10/12/2005#
dt2 = fomat$(dt1, "m/d/yyyy")
dt3 = dt1
debug.print dt1, dt2, dt3

--
Roy-Vidar

Nov 28 '05 #5
I'll always use global variables in any future projects to hold date
values rather than populating text fields on forms. That's after many
days and hours of debugging. Never again!
What I can't figure out is why, in a form's property sheet/input
parameters, when set to int'l time formats:
@StartDate = Date() does not work but @StartDate = Format(Date(),
"m/d/yyyy hh:nn:ss AM/PM") does

Nov 28 '05 #6
Are you using an ADP?
Is this MS-SQL?

Nov 28 '05 #7
Yes MS-SQL 2000, Access 2000 ADP/ADE

Nov 28 '05 #8
I think I have decided in future projects the following scheme would be
better overall:

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. In this way, the stored
procedure would use parameters like @StartDays int, @EndDays int
instead of @StartDate datetime, @EndDate datetime. Then use GETDATE()
in the stored procedure and DATEADD to rebuild the dates.

As an example, if I want to look at something where tomorrow's date
would have been the parmaeter I'd just pass 1 instead of date()+1. For
a date range of yesterday through two days from now, I'd pass
parameters of -1 and 2 instead of date()-1 and date()+2. I think
overall, this would simplify the whole process - never using date
parameters.

Nov 28 '05 #9
Well, I should have noticed that you said Stored Procedures in your
original post.

TTBOMR input parameters are strings.

@StartDate = Date() might not produce a great string while @StartDate
= Format(Date(),
"m/d/yyyy hh:nn:ss AM/PM") does.

When working with ADPs and MS-SQL one often has to deal with the fact
that Access and JET are inter-related, while Access and MS-SQL have
nothing to do with each other.

Input parameters are one of the really obtuse features of ADP, as you
seem to be finding out. (I've found them to be so ugly that I've forced
them from my mind, which is why I said, TTBOMR").

If you do a google groups search on this topic you will gind many tales
of woe and much gnanching of teeth.

Nov 28 '05 #10
I wrote one reply and removed it.
Input Parameters have been, for me, very gnarly things.
I have been most successful when remembering that they must be strings
which MS-SQL can understand.
So what will
@StartDate = Date()
return? I don't know. On my computer it returns
@StartDate = 2005-11-28
MS-SQL (or Access) doesn't know that I want it to convert 2005-11-28 to
a date. But it will handle
'2005-11-28'
and
#2005-11-28#
and I expect it will also handle the dates expressed as
#mm/dd/yyyy#

Nov 28 '05 #11
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

"Lyle Fairfield" <ly***********@aim.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
I wrote one reply and removed it.
Input Parameters have been, for me, very gnarly things.
I have been most successful when remembering that they must be strings
which MS-SQL can understand.
So what will
@StartDate = Date()
return? I don't know. On my computer it returns
@StartDate = 2005-11-28
MS-SQL (or Access) doesn't know that I want it to convert 2005-11-28 to
a date. But it will handle
'2005-11-28'
and
#2005-11-28#
and I expect it will also handle the dates expressed as
#mm/dd/yyyy#

Nov 29 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
15
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to...
7
by: Niall Porter | last post by:
Hi all, I'm building an ASP app on a Windows 2000/IIS machine which interfaces with our SQL Server 2000 database via OLE DB. Since we're based in the UK I want the users to be able to type in...
2
by: Aloof | last post by:
Using Access 2000 Windows Server 2003 The following code worked fine until we moved hosting companies StartDate = Request.Form("StartDateMonth") & "/" & Request.Form ("StartDateDay") & "/" &...
4
by: Matteo | last post by:
Hy everybody. I'm not a html writer, but a sysadmin who's trying to help a user able to compile an online form with IE but not with Mozilla (Moz1.6, Ns7.1, Firefox 0.8+) due to a javascript date...
5
by: DataB | last post by:
Hi everyone, I have this piece of VBA script: ' checking the DOB field to see if we constrain on the date If Len(Me.EmpDOBTxt & "") > 0 Then strWhere = strWhere & " AND . <= #" & Me.DOBTxt &...
2
by: Julie Wardlow | last post by:
Help! I am calculating a future date using the DateAdd function in a query (the calculation also involves an IIf statement), and have managed to get this formula to produce the required result....
20
by: andreas | last post by:
When I copy a vb.net project using date formats from one PC with a windows date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I get errors. How can I change for a while in the...
10
by: WebCM | last post by:
There is a function: http://paste.ubuntu.com/21865 It needs GMT date in YYYY-MM-DD HH:MM:SS format - in SQL: datetime. If date is the same as today, the function returns "Today". There is one...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.