Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default Converting datetime from character string

Hi,

I'm trying to import data from a MS SQL 2005 server. But I'm having
trouble with datetime:
When I give the date hardcoded (e.g. 2007-11-10) for "MyDate" in the
query it works fine.

Stepping true code below gives the value "#10-11-2007#" for MyDate.
Even after giving it a new NumberFormat

This is what I got sofar:
Dim MyDate
Range("A1").Select
Selection.NumberFormat = "yyyy/mm/dd"
MyDate = ActiveCell

With ActiveSheet.QueryTables.Add(Connection:= _

"ODBC;DSN=XXXX;UID=Productie;PWD=XXXXX;APP=Test;WS ID=;DATABASE=XXXX" _
, Destination:=Range("A2"))
.CommandText = Array( _
"SELECT O.OrderId, O.DeliveryDate, O.SACity, FROM Orders O
WHERE (O.DeliveryDate'MyDate')
)

Any idee would be great,
Giel

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 145
Default Converting datetime from character string

Try something similar to:

MyDate = Format(ActiveCell, "yyyy/mm/dd")

--


Damon Longworth - Microsoft Excel MVP

2007 Excel / Access User Conference

Cambridge, England - Nov 29 - Dec 1, 2007


2008 Excel / Access User Conference

Sydney, Australia - Tentatively March 12-14, 2008
www.ExcelUserConference.com/


wrote in message
ups.com...
Hi,

I'm trying to import data from a MS SQL 2005 server. But I'm having
trouble with datetime:
When I give the date hardcoded (e.g. 2007-11-10) for "MyDate" in the
query it works fine.

Stepping true code below gives the value "#10-11-2007#" for MyDate.
Even after giving it a new NumberFormat

This is what I got sofar:
Dim MyDate
Range("A1").Select
Selection.NumberFormat = "yyyy/mm/dd"
MyDate = ActiveCell

With ActiveSheet.QueryTables.Add(Connection:= _

"ODBC;DSN=XXXX;UID=Productie;PWD=XXXXX;APP=Test;WS ID=;DATABASE=XXXX" _
, Destination:=Range("A2"))
.CommandText = Array( _
"SELECT O.OrderId, O.DeliveryDate, O.SACity, FROM Orders O
WHERE (O.DeliveryDate'MyDate')
)

Any idee would be great,
Giel


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default Converting datetime from character string

Sorry, this is not working

Regards Giel


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default Converting datetime from character string

On 13 nov, 14:44, "
wrote:
Sorry, this is not working

Regards Giel


I have changed MyDate into a Double
This gives the proper value when stepping through the code.
But it does not give the value to MyDate in the Query.

Is there a way to solve this?

Giel

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default Converting datetime from character string

On 13 nov, 15:02, "
wrote:
On 13 nov, 14:44, "

wrote:
Sorry, this is not working


Regards Giel


I have changed MyDate into a Double
This gives the proper value when stepping through the code.
But it does not give the value to MyDate in the Query.

Is there a way to solve this?

Giel


After a little search I found the trick:

'" & MyDate & "'

Now it works fine



Reply
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
find a character in a string kevcar40 Excel Discussion (Misc queries) 4 June 5th 07 12:10 PM
Excel-Match 1st text character in a string to a known character? bushlite Excel Worksheet Functions 2 January 15th 07 06:36 PM
MS Query DateTime String Dean Excel Worksheet Functions 1 January 23rd 06 12:07 PM
Splitting Character String mcertini Excel Worksheet Functions 2 September 12th 05 09:41 AM
Find nth instance of a character in a string Francis Hayes (The Excel Addict) Excel Discussion (Misc queries) 7 January 21st 05 03:44 PM


All times are GMT +1. The time now is 02:50 PM.

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"