problem inputing current time into MSSQL db

ssfftt

Well-known member
Joined
Oct 27, 2005
Messages
163
Programming Experience
1-3
[solved]problem inputing current time into MSSQL db

I have 2 columns on a table, called "curDate" and "curTime", i want curDate contains the current date, and curTime contains the current time. I have these 2 lines of code that updates those 2 columns in my MSSQL db table.after execute the command, when i retrieve all rows, the curDate column displays correct date format "22/11/05", however, the curTime column got the value " 22/11/05, 00:11:35 AM". why is that? did i make any mistake? the clolumn curTime is type of "datetime" in db. please help, i want the curTime column only gets the value of "00:11:35 AM", that is, only the time.
VB.NET:
            ModuleUser.frmTesting.SqlCommandAddResult.Parameters("@STARTDATE").Value = Now.ToLongDateString()            ModuleUser.frmTesting.SqlCommandAddResult.Parameters("@STARTTIME").Value = Now.ToLongTimeString()
 
Last edited:
well, i did the change suggested, and the new data inserted into curTime was shown as this: "NOV 22 2". I am expecting the time: " 12:25:18 PM", plz help
 
more interesting is that curTime on db table is set to datetime, length 8, how can it end up storing data like " 22/11/05, 00:11:35 AM"???????
 
Friend i am doing this for ages and it works just flawless ...

for instance you want to insert only time:
VB.NET:
Dim myTime as DateTime = Date.Now.ToShortTimeString '11:11 AM
 
[SIZE=2]myCommand = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlCommand("INSERT INTO testTable (test, myOnlyTime) VALUES('something', '" & myTime & "')", myConn)[/SIZE]
[SIZE=2]
[/SIZE]
About the datetime datatype, well it's not considered like a string but rather it holds a value so you shouldn't worry much about that :D

Regards ;)
 
thx kulrom again, I am using australian time format, maybe that's the difference. one more question, the reason why i want to have a startdate and a starttime is just for identifying a specific record. do u think i really need both? or maybe the starttime will do the job (since it is stored in db as " 22/11/05, 00:11:35 AM")?btw, i just noticed that u from Macedonia, same country where my landlord from. he's been living in aus for more than 40 yrs, he went back to Macedonia 2 yrs ago and got his first son a wife there. we had a Macedonian wedding here, and learnt the dancing, awesome night!
 
Say hi to your landlord :D
About your problem; 1st off let's str8 that it doesn't matter is it Australian or American or any other datetime format.

About do you need both starttime and also startdate, well it depends on what do you want to do with these values later in your application but mainly you can go for only one field that holds something like "22/11/05, 00:11:35 AM" ... it will be enough in most of the cases like if you want to perform some calculations or if you want to produce a report related to exactly time/period etc. ... means i don't see a reason why you would keep the both fields.

Regards ;)
 
Back
Top