Visual Basic for Applications (VBA)


ADP Project Office 2003 and SQL Server 2000 datetime conversion error in where clause yyyy-mm-dd to yyyy-dd-mm


HI,
i'am mantaining an Access 2003 .adp project. This software is connected to sql2000 database server with ADODB. The client and server database Language are all in Italian and development station too !
On one mask of project i have a set of search conditions , including date start and date end.
This conditions fill an sql string like this
"SELECT a,b,c,d FROM myTable WHERE myTable.e <= '" & Format(dateStart,'YYYY-MM-DD HH:MM:NN') & "' and myTable.f >= '" & Format(dateEnd,'YYYY-MM-DD HH:MM:NN') &"'"
Ok when a date has day > of month i receive this exception:
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. ()
It's correct to use non ambiguous format like this ?
"SELECT a,b,c,d FROM myTable WHERE myTable.e <= '" & Format(dateStart,'YYYYMMDD HH:MM:NN') & "' and myTable.f >= '" & Format(dateEnd,'YYYYMMDD HH:MM:NN') &"'"
or this?
"SELECT a,b,c,d FROM myTable WHERE myTable.e <= convert(datetime'" & Format(dateStart,'YYYY-MM-DD HH:MM:NN') & "',120) and myTable.f >= convert(datetime,'" & Format(dateEnd,'YYYY-MM-DD HH:MM:NN') &"',120)"
Their work both, but i'm not sure which is the better choice
Thank you in advance
V.
lluthus
I always use a date format of 'YYYY-MM-DD' as it works reliably (for me) and works for any country's date format. The convert format works as well, but the first is simpler, easier to read and so easier and cheaper to maintain so it has my vote.Rod Gill
The one and only Project VBA Book
Rod Gill Project Management

Related Links

Using a condition of =H1<H2 or =H1>H2, How to format H1 instead of H2?
Conditionally formatting a looped range of cells based on value in other cell in VBA
How to get the List of Visible Items from a Pivot Field using VBA
How to run a macro when a Filter is applied on Particular Pivot Field
Add a new property to an existing object
How to Allocate Input Numeric digit to Concerned Numeric header Column
Range referencing in Copy and Paste Formats
VBA6 trouble in WINDOWS 10
VBA dynamic formula reference
Printing Userform
Sorting and selecting cells based off name.
How to tune auto filter option for our need???
VBA Loggin into secure websites
MS Project import of custom field data from Excel resulting in Run-time error 462
How to write a filtered data as a text file using macros???
Block specific site and show custom content?

Categories

MSDN
Windows Phone Development
Visual Studio Design a...
Machine Translation an...
Bing
Archived Forums C-D
Archived Forums I-L
OneDrive Development
Microsoft Partner Center
Visual Studio Tools fo...
Visual Studio Graphics...
Dev Center App
XboxLiveDevelopment
Windows Desktop Perfmo...
Message Analyzer
Open XML Format SDK
Office 365 for Developers
SharePoint 2010 - Deve...
Azure Virtual Machines
Azure Backup
Azure Scripting and Co...
Azure Notification Hubs
Azure Logic Apps
Azure Service Fabric
Azure SQL Data Warehouse
Azure Functions
Windows Presentation F...
Common Language Runtim...
Team Foundation Server...
Architecture General
Software Modeling Tools
BizTalk Server RFID
The Forum of Sho
HealthVault Developer
Scripting
Microsoft Translator D...
Microsoft Translator H...
Visual Basic for Appli...
Training and Certifica...
SyncFx - SyncToy-File ...
Microsoft Robotics - S...
Visual Studio Smart De...
Visual Studio Smart De...
SQL Server SMO/DMO
SQL Server Replication
SQL Server Notificatio...
SQL Server Master Data...
SQL Server Manageability
SQL Server Distributed...
Windows Embedded Compa...
SQL Server 2012 PowerP...
SQL Server 2012 High A...
SQL Server 2012 Spatia...
SQL Server 2012 PowerP...
Windows Forms Data Con...
SDK for Home Server 20...
Live Connect (Archived)
Windows Live ID: Devel...
Script Junkie Discussion
Speech Service for Dev...
Bing Maps REST, SOAP, ...
Microsoft Unified Comm...
Programming Silverligh...
Visual Studio & Silver...
MVVM / ViewModel Patte...
Expression Studio with...
Expression Design
Retired SharePoint Bus...
Retired SharePoint Exc...
Retired SharePoint Acc...
.NET Framework 4 Appli...
.NET Framework 4 Relea...
Axum Incubation Project
Building Development a...
Audio API and Programm...
Building Windows Store...
Building Windows Store...
Commerce Server 2002 a...
Developer Documentatio...
Dryad, DSC, and DryadL...
Game Technologies: Gen...
Face Tracking – Kinect...
Innovate on Office
Managed Extensibility ...
Microsoft Unified Comm...
Microsoft "Data Explor...
patterns & practices: ...
Search Server: Frequen...
Search, Organize, and ...
Share your How to samp...
Surface Application De...
SQL Creation
SQL Server 2014 In Azu...
Team Foundation Server...
Tools for Windows Phon...
Visual Basic for Appli...
Visual Basic IDE
Visual Basic Interop a...
Visual Studio Database...
Visual Studio Lab Mana...
Visual Studio Team Sys...
Visual Studio Online "...
Windows Error Reportin...
Windows Live Data Deve...
Tools for Windows Stor...
Windows IoT
Cortana Skills Kit

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile