#1   Report Post  
Posted to microsoft.public.excel.programming
EKJ EKJ is offline
external usenet poster
 
Posts: 7
Default Date format

Hello
I have made an Visual Basic script where i have a date in this formet
09-03-2007, this i am writing to an excel sheet witch is formatted as short
date, but my problem is that it take it as a calculation so what i get is the
number -2001.

How can this be
--
EKJ
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Date format

How are you "writing to an excel sheet" ?

NickHK

"EKJ" wrote in message
...
Hello
I have made an Visual Basic script where i have a date in this formet
09-03-2007, this i am writing to an excel sheet witch is formatted as

short
date, but my problem is that it take it as a calculation so what i get is

the
number -2001.

How can this be
--
EKJ



  #3   Report Post  
Posted to microsoft.public.excel.programming
EKJ EKJ is offline
external usenet poster
 
Posts: 7
Default Date format

Hello

I am using a Siemens product named WinCC where i have made a script like this


Dim OmkoerslerD
Dim GodeEmnerD
Dim BrokD
Dim ProdD
Dim IkkeRegTidD
Dim OmstillingD
Dim OmkoerselD
Dim moedeD
Dim LaveAndetD
Dim nedBrakD
Dim rengoeringD
Dim mglVarerD
Dim smaStopD
Dim BemandetD
Dim DatoD
Dim DatoA
Dim ProdA
Dim IkkeRegTidA
Dim DatoN
Dim ProdN
Dim IkkeRegTidN
Dim Dato_Test

OmkoerslerD = OmkoerslerDag
GodeEmnerD = GodeEmnerDag
BrokD = BrokDag
ProdD = SmartTags("ProdDag")
IkkeRegTidD = SmartTags("IkkeRegTIdDag")
OmstillingD = SmartTags("OmstillingDag")
OmkoerselD = SmartTags("OmkoerselDag")
moedeD = SmartTags("moededag")
LaveAndetD = SmartTags("laveAndetDag")
nedBrakD = SmartTags("nedBrakDag")
rengoeringD = SmartTags("rengoeringDag")
mglVarerD = SmartTags("mglVarerDag")
smaStopD = SmartTags("smaStopDag")
BemandetD = SmartTags("BemandetDag")
DatoD = FormatDateTime(Date, 1)
DatoA = Date
ProdA = SmartTags("ProdAften")
ProdA = SmartTags("IkkeRegTidAften")
DatoN = Date
ProdA = SmartTags("ProdNat")
ProdA = SmartTags("IkkeRegTidNat")

SmartTags("EKJ_DAG") = Int(Day(Date))
SmartTags("EKJ_AAR") = Int(Year(Date))
SmartTags("EKJ_MDR") = Int(Month(Date))
SmartTags("EKJ_DATO") = (EKJ_DAG&"/"&EKJ_MDR&"/"&EKJ_AAR)
Dato_Test = FormatNumber

Dim objConnection

Dim strConnectionString


Dim strSQL

Dim objCommand
strConnectionString = "Provider=MSDASQL;DSN=OEE_05681;UID=;PWD=;"


strSQL = "INSERT INTO Dag
(DataAARD,DataMDRD,DataDAGD,ProdDag,IkkeRegTidDag, OmstillingDag,OmkoerselDag,moedeDag,laveAndetDag,n edBrakDag,rengoeringDag,mglVarerDag,smaStopDag,Bem andetDag,GodeEmnerDag,OmkoerslerDag,BrokDag)
VALUES (" & DatoD & "," & EKJ_MDR & "," & EKJ_DAG & "," & ProdD & "," &
IkkeRegTidD & "," & OmstillingD & "," & OmkoerselD & "," & moedeD & "," &
LaveAndetD & "," & nedBrakD & "," & rengoeringD & "," & mglVarerD & "," &
smaStopD & "," & BemandetD & "," & GodeEmnerD & "," & OmkoerslerD & "," &
BrokD & ");"


Set objConnection = CreateObject("ADODB.Connection")

objConnection.ConnectionString = strConnectionString

objConnection.Open

Set objCommand = CreateObject("ADODB.Command")

With objCommand

.ActiveConnection = objConnection

.CommandText = strSQL

End With

objCommand.Execute

Set objCommand = Nothing

objConnection.Close

Set objConnection = Nothing

--
EKJ


"NickHK" skrev:

How are you "writing to an excel sheet" ?

NickHK

"EKJ" wrote in message
...
Hello
I have made an Visual Basic script where i have a date in this formet
09-03-2007, this i am writing to an excel sheet witch is formatted as

short
date, but my problem is that it take it as a calculation so what i get is

the
number -2001.

How can this be
--
EKJ




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Date format

I assume you are working in Excel VBA ?
It would help to type your variables. Otherwise everything is a Variant and
therefore difficult to know exact what value it contains. e.g.
Dim DatoD As Date
'etc

Also, maybe dates need to be surrounded in "#". e.g.
VALUES (#" & DatoD & "#," &

Add a <Debug.Print strSQL to see exact what you are using as the SQL text.

NickHK

"EKJ" wrote in message
...
Hello

I am using a Siemens product named WinCC where i have made a script like

this


Dim OmkoerslerD
Dim GodeEmnerD
Dim BrokD
Dim ProdD
Dim IkkeRegTidD
Dim OmstillingD
Dim OmkoerselD
Dim moedeD
Dim LaveAndetD
Dim nedBrakD
Dim rengoeringD
Dim mglVarerD
Dim smaStopD
Dim BemandetD
Dim DatoD
Dim DatoA
Dim ProdA
Dim IkkeRegTidA
Dim DatoN
Dim ProdN
Dim IkkeRegTidN
Dim Dato_Test

OmkoerslerD = OmkoerslerDag
GodeEmnerD = GodeEmnerDag
BrokD = BrokDag
ProdD = SmartTags("ProdDag")
IkkeRegTidD = SmartTags("IkkeRegTIdDag")
OmstillingD = SmartTags("OmstillingDag")
OmkoerselD = SmartTags("OmkoerselDag")
moedeD = SmartTags("moededag")
LaveAndetD = SmartTags("laveAndetDag")
nedBrakD = SmartTags("nedBrakDag")
rengoeringD = SmartTags("rengoeringDag")
mglVarerD = SmartTags("mglVarerDag")
smaStopD = SmartTags("smaStopDag")
BemandetD = SmartTags("BemandetDag")
DatoD = FormatDateTime(Date, 1)
DatoA = Date
ProdA = SmartTags("ProdAften")
ProdA = SmartTags("IkkeRegTidAften")
DatoN = Date
ProdA = SmartTags("ProdNat")
ProdA = SmartTags("IkkeRegTidNat")

SmartTags("EKJ_DAG") = Int(Day(Date))
SmartTags("EKJ_AAR") = Int(Year(Date))
SmartTags("EKJ_MDR") = Int(Month(Date))
SmartTags("EKJ_DATO") = (EKJ_DAG&"/"&EKJ_MDR&"/"&EKJ_AAR)
Dato_Test = FormatNumber

Dim objConnection

Dim strConnectionString


Dim strSQL

Dim objCommand
strConnectionString = "Provider=MSDASQL;DSN=OEE_05681;UID=;PWD=;"


strSQL = "INSERT INTO Dag

(DataAARD,DataMDRD,DataDAGD,ProdDag,IkkeRegTidDag, OmstillingDag,OmkoerselDag
,moedeDag,laveAndetDag,nedBrakDag,rengoeringDag,mg lVarerDag,smaStopDag,Beman
detDag,GodeEmnerDag,OmkoerslerDag,BrokDag)
VALUES (" & DatoD & "," & EKJ_MDR & "," & EKJ_DAG & "," & ProdD & "," &
IkkeRegTidD & "," & OmstillingD & "," & OmkoerselD & "," & moedeD & "," &
LaveAndetD & "," & nedBrakD & "," & rengoeringD & "," & mglVarerD & "," &
smaStopD & "," & BemandetD & "," & GodeEmnerD & "," & OmkoerslerD & "," &
BrokD & ");"


Set objConnection = CreateObject("ADODB.Connection")

objConnection.ConnectionString = strConnectionString

objConnection.Open

Set objCommand = CreateObject("ADODB.Command")

With objCommand

.ActiveConnection = objConnection

.CommandText = strSQL

End With

objCommand.Execute

Set objCommand = Nothing

objConnection.Close

Set objConnection = Nothing

--
EKJ


"NickHK" skrev:

How are you "writing to an excel sheet" ?

NickHK

"EKJ" wrote in message
...
Hello
I have made an Visual Basic script where i have a date in this formet
09-03-2007, this i am writing to an excel sheet witch is formatted as

short
date, but my problem is that it take it as a calculation so what i get

is
the
number -2001.

How can this be
--
EKJ






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 253
Default Date format

Hi,

XL expect a date to be in the format as defined in the regional setting.(/
or - or " ")
Try to use DateSerial function
Regards
JY
"EKJ" wrote in message
...
Hello

I am using a Siemens product named WinCC where i have made a script like
this


Dim OmkoerslerD
Dim GodeEmnerD
Dim BrokD
Dim ProdD
Dim IkkeRegTidD
Dim OmstillingD
Dim OmkoerselD
Dim moedeD
Dim LaveAndetD
Dim nedBrakD
Dim rengoeringD
Dim mglVarerD
Dim smaStopD
Dim BemandetD
Dim DatoD
Dim DatoA
Dim ProdA
Dim IkkeRegTidA
Dim DatoN
Dim ProdN
Dim IkkeRegTidN
Dim Dato_Test

OmkoerslerD = OmkoerslerDag
GodeEmnerD = GodeEmnerDag
BrokD = BrokDag
ProdD = SmartTags("ProdDag")
IkkeRegTidD = SmartTags("IkkeRegTIdDag")
OmstillingD = SmartTags("OmstillingDag")
OmkoerselD = SmartTags("OmkoerselDag")
moedeD = SmartTags("moededag")
LaveAndetD = SmartTags("laveAndetDag")
nedBrakD = SmartTags("nedBrakDag")
rengoeringD = SmartTags("rengoeringDag")
mglVarerD = SmartTags("mglVarerDag")
smaStopD = SmartTags("smaStopDag")
BemandetD = SmartTags("BemandetDag")
DatoD = FormatDateTime(Date, 1)
DatoA = Date
ProdA = SmartTags("ProdAften")
ProdA = SmartTags("IkkeRegTidAften")
DatoN = Date
ProdA = SmartTags("ProdNat")
ProdA = SmartTags("IkkeRegTidNat")

SmartTags("EKJ_DAG") = Int(Day(Date))
SmartTags("EKJ_AAR") = Int(Year(Date))
SmartTags("EKJ_MDR") = Int(Month(Date))
SmartTags("EKJ_DATO") = (EKJ_DAG&"/"&EKJ_MDR&"/"&EKJ_AAR)
Dato_Test = FormatNumber

Dim objConnection

Dim strConnectionString


Dim strSQL

Dim objCommand
strConnectionString = "Provider=MSDASQL;DSN=OEE_05681;UID=;PWD=;"


strSQL = "INSERT INTO Dag
(DataAARD,DataMDRD,DataDAGD,ProdDag,IkkeRegTidDag, OmstillingDag,OmkoerselDag,moedeDag,laveAndetDag,n edBrakDag,rengoeringDag,mglVarerDag,smaStopDag,Bem andetDag,GodeEmnerDag,OmkoerslerDag,BrokDag)
VALUES (" & DatoD & "," & EKJ_MDR & "," & EKJ_DAG & "," & ProdD & "," &
IkkeRegTidD & "," & OmstillingD & "," & OmkoerselD & "," & moedeD & "," &
LaveAndetD & "," & nedBrakD & "," & rengoeringD & "," & mglVarerD & "," &
smaStopD & "," & BemandetD & "," & GodeEmnerD & "," & OmkoerslerD & "," &
BrokD & ");"


Set objConnection = CreateObject("ADODB.Connection")

objConnection.ConnectionString = strConnectionString

objConnection.Open

Set objCommand = CreateObject("ADODB.Command")

With objCommand

.ActiveConnection = objConnection

.CommandText = strSQL

End With

objCommand.Execute

Set objCommand = Nothing

objConnection.Close

Set objConnection = Nothing

--
EKJ


"NickHK" skrev:

How are you "writing to an excel sheet" ?

NickHK

"EKJ" wrote in message
...
Hello
I have made an Visual Basic script where i have a date in this formet
09-03-2007, this i am writing to an excel sheet witch is formatted as

short
date, but my problem is that it take it as a calculation so what i get
is

the
number -2001.

How can this be
--
EKJ








  #6   Report Post  
Posted to microsoft.public.excel.programming
EKJ EKJ is offline
external usenet poster
 
Posts: 7
Default Date format

Hello again

This worked with #" & DatoD & "#

Thank you verry much and have a nice week-end.
EKJ


"NickHK" skrev:

I assume you are working in Excel VBA ?
It would help to type your variables. Otherwise everything is a Variant and
therefore difficult to know exact what value it contains. e.g.
Dim DatoD As Date
'etc

Also, maybe dates need to be surrounded in "#". e.g.
VALUES (#" & DatoD & "#," &

Add a <Debug.Print strSQL to see exact what you are using as the SQL text.

NickHK

"EKJ" wrote in message
...
Hello

I am using a Siemens product named WinCC where i have made a script like

this


Dim OmkoerslerD
Dim GodeEmnerD
Dim BrokD
Dim ProdD
Dim IkkeRegTidD
Dim OmstillingD
Dim OmkoerselD
Dim moedeD
Dim LaveAndetD
Dim nedBrakD
Dim rengoeringD
Dim mglVarerD
Dim smaStopD
Dim BemandetD
Dim DatoD
Dim DatoA
Dim ProdA
Dim IkkeRegTidA
Dim DatoN
Dim ProdN
Dim IkkeRegTidN
Dim Dato_Test

OmkoerslerD = OmkoerslerDag
GodeEmnerD = GodeEmnerDag
BrokD = BrokDag
ProdD = SmartTags("ProdDag")
IkkeRegTidD = SmartTags("IkkeRegTIdDag")
OmstillingD = SmartTags("OmstillingDag")
OmkoerselD = SmartTags("OmkoerselDag")
moedeD = SmartTags("moededag")
LaveAndetD = SmartTags("laveAndetDag")
nedBrakD = SmartTags("nedBrakDag")
rengoeringD = SmartTags("rengoeringDag")
mglVarerD = SmartTags("mglVarerDag")
smaStopD = SmartTags("smaStopDag")
BemandetD = SmartTags("BemandetDag")
DatoD = FormatDateTime(Date, 1)
DatoA = Date
ProdA = SmartTags("ProdAften")
ProdA = SmartTags("IkkeRegTidAften")
DatoN = Date
ProdA = SmartTags("ProdNat")
ProdA = SmartTags("IkkeRegTidNat")

SmartTags("EKJ_DAG") = Int(Day(Date))
SmartTags("EKJ_AAR") = Int(Year(Date))
SmartTags("EKJ_MDR") = Int(Month(Date))
SmartTags("EKJ_DATO") = (EKJ_DAG&"/"&EKJ_MDR&"/"&EKJ_AAR)
Dato_Test = FormatNumber

Dim objConnection

Dim strConnectionString


Dim strSQL

Dim objCommand
strConnectionString = "Provider=MSDASQL;DSN=OEE_05681;UID=;PWD=;"


strSQL = "INSERT INTO Dag

(DataAARD,DataMDRD,DataDAGD,ProdDag,IkkeRegTidDag, OmstillingDag,OmkoerselDag
,moedeDag,laveAndetDag,nedBrakDag,rengoeringDag,mg lVarerDag,smaStopDag,Beman
detDag,GodeEmnerDag,OmkoerslerDag,BrokDag)
VALUES (" & DatoD & "," & EKJ_MDR & "," & EKJ_DAG & "," & ProdD & "," &
IkkeRegTidD & "," & OmstillingD & "," & OmkoerselD & "," & moedeD & "," &
LaveAndetD & "," & nedBrakD & "," & rengoeringD & "," & mglVarerD & "," &
smaStopD & "," & BemandetD & "," & GodeEmnerD & "," & OmkoerslerD & "," &
BrokD & ");"


Set objConnection = CreateObject("ADODB.Connection")

objConnection.ConnectionString = strConnectionString

objConnection.Open

Set objCommand = CreateObject("ADODB.Command")

With objCommand

.ActiveConnection = objConnection

.CommandText = strSQL

End With

objCommand.Execute

Set objCommand = Nothing

objConnection.Close

Set objConnection = Nothing

--
EKJ


"NickHK" skrev:

How are you "writing to an excel sheet" ?

NickHK

"EKJ" wrote in message
...
Hello
I have made an Visual Basic script where i have a date in this formet
09-03-2007, this i am writing to an excel sheet witch is formatted as
short
date, but my problem is that it take it as a calculation so what i get

is
the
number -2001.

How can this be
--
EKJ






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
permanent conversion of 1904 date format to 1900 date format Jos Excel Worksheet Functions 4 November 26th 15 02:48 PM
convert serial date format to normal date format Flagworld Excel Discussion (Misc queries) 3 September 23rd 08 01:32 PM
Convert date + time text format to date format Paul Ho Excel Worksheet Functions 2 May 22nd 07 05:47 PM
code to convert date from TEXT format (03-02) to DATE format (200203) Gauthier[_2_] Excel Programming 0 September 22nd 04 03:26 PM
Change a date in text format xx.xx.20xx to a recognised date format concatenator Excel Programming 1 November 24th 03 11:33 PM


All times are GMT +1. The time now is 08:59 PM.

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

About Us

"It's about Microsoft Excel"