PC Review Forums Newsgroups Microsoft DotNet Microsoft VB .NET DATE HELLLPPPP

Reply

DATE HELLLPPPP

 
Thread Tools Rate Thread
Old 13-01-2006, 03:36 PM   #1
Adrian
Guest
 
Posts: n/a
Default DATE HELLLPPPP


Hi
I have a vb.net app asp.net 1.1 that uses "NOW" to get the date and the
uses a sql statement to write it to an MS SQL server remotely hosted!

Well the date has flipped to 13/01/2006 the data base wants it in US format
what's the best way of changing it?!

I tried format(now, "MM/DD/YYYY HH:MM:SS") but this just gives me an error
Cast from string "01/DD/YYYY 15:01" to type 'Date' is not valid.


HELLPP


  Reply With Quote
Old 13-01-2006, 04:01 PM   #2
Cor Ligthert [MVP]
Guest
 
Posts: n/a
Default Re: DATE HELLLPPPP

Adrian,

Be aware that the IDE from VBNet shows dates between ## in USA format.
(Don't be confused if you use C# as well, that IDE shows the datetime in
your local setting).

The actual DateTimes are in ticks (Starting in 1753 for SQL server and at
1-1-1 for Net).

Therefore try to avoid any fixed changes from a datetime, normally Net does
that for you.

Cor


  Reply With Quote
Old 13-01-2006, 04:14 PM   #3
Armin Zingler
Guest
 
Posts: n/a
Default Re: DATE HELLLPPPP

"Adrian" <Adrian@nospamhotmail.com.uk> schrieb
> Hi
> I have a vb.net app asp.net 1.1 that uses "NOW" to get the date
> and the uses a sql statement to write it to an MS SQL server
> remotely hosted!
>
> Well the date has flipped to 13/01/2006 the data base wants it in US
> format what's the best way of changing it?!
>
> I tried format(now, "MM/DD/YYYY HH:MM:SS") but this just gives me
> an error Cast from string "01/DD/YYYY 15:01" to type 'Date' is not
> valid.


Use parameters:

sqlcommand.parameters.add("@param", sqldatatype.datetime").value = now


Armin



  Reply With Quote
Old 13-01-2006, 06:11 PM   #4
Adrian
Guest
 
Posts: n/a
Default Re: DATE HELLLPPPP

Hi,
Thanks, I got around it for now by using substring to re construct the
date! as this SQL is new to me

So if I use parameters how do I do it?

is each part of the query constructed using it?

how would i use it to say do this:
Cmd = New SqlCommand(strSql, Conn)
strSql = "INSERT INTO DownloadLog(Stamp, XXX, IPAddress, YYY) VALUES('" &
dateTStamp & "', '" & strXXX & " ','" & strIP & "' ,'" & strYYY & "')"
Conn.Open()
Cmd.ExecuteNonQuery()

thanks


"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:un8mXqGGGHA.208@tk2msftngp13.phx.gbl...
> "Adrian" <Adrian@nospamhotmail.com.uk> schrieb
>> Hi
>> I have a vb.net app asp.net 1.1 that uses "NOW" to get the date
>> and the uses a sql statement to write it to an MS SQL server
>> remotely hosted!
>>
>> Well the date has flipped to 13/01/2006 the data base wants it in US
>> format what's the best way of changing it?!
>>
>> I tried format(now, "MM/DD/YYYY HH:MM:SS") but this just gives me
>> an error Cast from string "01/DD/YYYY 15:01" to type 'Date' is not
>> valid.

>
> Use parameters:
>
> sqlcommand.parameters.add("@param", sqldatatype.datetime").value = now
>
>
> Armin
>
>
>



  Reply With Quote
Old 13-01-2006, 06:44 PM   #5
Armin Zingler
Guest
 
Posts: n/a
Default Re: DATE HELLLPPPP

"Adrian" <Adrian@nospamhotmail.com.uk> schrieb
> Hi,
> Thanks, I got around it for now by using substring to re construct
> the date! as this SQL is new to me
>
> So if I use parameters how do I do it?
>
> is each part of the query constructed using it?
>
> how would i use it to say do this:
> Cmd = New SqlCommand(strSql, Conn)
> strSql = "INSERT INTO DownloadLog(Stamp, XXX, IPAddress, YYY)
> VALUES('" & dateTStamp & "', '" & strXXX & " ','" & strIP & "' ,'" &
> strYYY & "')" Conn.Open()
> Cmd.ExecuteNonQuery()



You'll find many samples if you press <F1>. ;-)


strSql = "INSERT INTO DownloadLog(Stamp, XXX, IPAddress, YYY) VALUES(@Stamp,
@xxx, @ipadress, @yyy)
Cmd = New SqlCommand(strSql, Conn)
with cmd.parameters
.add("@stamp", sqldbtype.datetime).value = stamp
.add("@xxx", sqldbtype.varchar).value = xxx
.add("@ipaddress", sqldbtype.varchar).value = ipaddress
.add("@yyy", sqldbtype.varchar).value = yyy
end with

Conn.Open()
Cmd.ExecuteNonQuery()


Variable stamp should be declare as DateTime, the others as string. I
assumed that xxx, ipaddress and yyy are varchar in the database.


If you will have further ADO.Net (language unrelated) questions,
microsoft.public.dotnet.framework.adonet is the best place to ask.


Armin

  Reply With Quote
Old 13-01-2006, 06:52 PM   #6
Adrian
Guest
 
Posts: n/a
Default Re: DATE HELLLPPPP

Great thanks for your help

"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:eNrauGHGGHA.2212@TK2MSFTNGP15.phx.gbl...
> "Adrian" <Adrian@nospamhotmail.com.uk> schrieb
>> Hi,
>> Thanks, I got around it for now by using substring to re construct
>> the date! as this SQL is new to me
>>
>> So if I use parameters how do I do it?
>>
>> is each part of the query constructed using it?
>>
>> how would i use it to say do this:
>> Cmd = New SqlCommand(strSql, Conn)
>> strSql = "INSERT INTO DownloadLog(Stamp, XXX, IPAddress, YYY)
>> VALUES('" & dateTStamp & "', '" & strXXX & " ','" & strIP & "' ,'" &
>> strYYY & "')" Conn.Open()
>> Cmd.ExecuteNonQuery()

>
>
> You'll find many samples if you press <F1>. ;-)
>
>
> strSql = "INSERT INTO DownloadLog(Stamp, XXX, IPAddress, YYY)
> VALUES(@Stamp, @xxx, @ipadress, @yyy)
> Cmd = New SqlCommand(strSql, Conn)
> with cmd.parameters
> .add("@stamp", sqldbtype.datetime).value = stamp
> .add("@xxx", sqldbtype.varchar).value = xxx
> .add("@ipaddress", sqldbtype.varchar).value = ipaddress
> .add("@yyy", sqldbtype.varchar).value = yyy
> end with
>
> Conn.Open()
> Cmd.ExecuteNonQuery()
>
>
> Variable stamp should be declare as DateTime, the others as string. I
> assumed that xxx, ipaddress and yyy are varchar in the database.
>
>
> If you will have further ADO.Net (language unrelated) questions,
> microsoft.public.dotnet.framework.adonet is the best place to ask.
>
>
> Armin



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off