LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Date Problem

I am writing some code in an Excel workbook that retrieves data from an
Access database. The SQL for the recordset is generated within the code and
is dependant upon two dates to define the period for which I want the data
returned
Code is thus (simplified)

Dim datStartDate as Date
Dim datEndDate as Date
Dim strSQL as String

datStartDate=DateSerial(Year(Date),Month(Date)-1,1) 'First of last month
datEndDate=DateSerial(Year(Date),Month(Date),0) 'Last day of last month

'I live in the UK so the date is returned as dd/mm/yyyy, but i need it
returned in
'the US format to apply to the SQL string, so

datStartDate=Format(datStartDate,"mm/dd/yyyy")
datEndDate=Format(datEndDate,"mm/dd/yyyy")

strSQL="SELECT SUM(ACTS) AS A FROM STATS WHERE ACT_DATE BETWEEN " _
& "#" & datStartDate & "# AND #" & datEndDate & "#"

Should work perfectly? No!
datStartDate returns 08/01/2004 (Date in US format)
But datEndDate returns 31/08/2004 (Not in US Format)

I have tried changing the date on my PC but the end date keeps being
returned in UK format and therefore being passed into the SQL string in this
manner. This is driving me nuts. Can anyone help.
TIA
Mark
Mark


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
date problem evilyn New Users to Excel 2 November 3rd 08 09:52 PM
Exel increment date problem wrt todays date. [email protected] Excel Worksheet Functions 1 November 11th 07 06:58 PM
Date Formula Problem - Leave date blank if Null Gayla Excel Worksheet Functions 5 April 24th 07 09:42 PM
DATE PROBLEM Malcolm Austin Excel Worksheet Functions 2 March 5th 07 11:28 AM
Date problem Jamie[_8_] Excel Programming 0 May 6th 04 08:24 AM


All times are GMT +1. The time now is 02:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"