473,770 Members | 5,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(StartDa te, "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:=Arr ay(StartDate, EndDate),
Options:=adExec uteNoRecords

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

Nov 28 '05 #1
11 1902
Lauren Quantrell wrote in message
<11************ *********@o13g2 000cwo.googlegr oups.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(StartDa te, "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:=Arr ay(StartDate, EndDate),
Options:=adExec uteNoRecords

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 = .createparamete r("MyDate", addate, adparaminput)
.parameters.app end 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 = .createparamete r("MyDate", addate, adparaminput)
.parameters.app end prm
.prm.value = (Format(Me.Star tDate, "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************ **********@z14g 2000cwz.googleg roups.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 = .createparamete r("MyDate", addate, adparaminput)
.parameters.app end prm
.prm.value = (Format(Me.Star tDate, "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.Star tDate, "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

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

Similar topics

8
9445
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 $ Last-Modified: $Date: 2003/10/28 19:48:44 $ Author: A.M. Kuchling <amk@amk.ca> Status: Draft Type: Standards Track
15
43016
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 mediate between webapps and arbitrary database backends using JDBC. I am very unwilling indeed to write special-case code for particular databases. Our code has worked satisfactorily with many databases, including many instances MS SQLServer 2000...
7
3166
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 dates in UK date format to input into the database. In Enterprise Manager on the SQL Server I can manually enter a record into a table and just type in a UK date (MM/DD/YYYY e.g. 25/12/2004) and it accepts it happily.
2
6182
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") & "/" & Request.Form("StartDateYear") EndDate = Request.Form("EndDateMonth") & "/" & Request.Form ("EndDateDay") & "/" & Request.Form("EndDateYear")
4
43537
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 check. Let's go straight to the point: <script language="JavaScript"> alert("Date: "+Date.parse("2000-01-01"))
5
1890
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 & "#" End If
2
6516
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. I then want to search through the records and select those with dates (as caluclated above) within a user defined range, and so I am using a parameter query. However, this query returns dates outside of the range and appears to have particular...
20
35629
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 project the date format in vb.code ( not in Windows) and how can I find out which date format the PC Windows is using. Thanks for any response
10
4025
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 problem. This function does not recognize time zones. How to adjust date to user's time zone? Is converting to timestamp() and then to format readable to visitors the one and only solution (e.g. strtotime() + date() OR DateTime object)? Perhaps,...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10231
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10005
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6679
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.