By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,304 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,304 IT Pros & Developers. It's quick & easy.

inserting string date and time into mssql database

P: 26
Hi All,

I have some problem in inserting date and time entered by user from the GUI into the form. Any idea on how this can be done?

Thank you

Regards,
Kencana
Feb 16 '08 #1
Share this Question
Share on Google+
9 Replies


ronverdonk
Expert 2.5K+
P: 4,258
How (in what format) does the user enter the date and the time?

Ronald
Feb 16 '08 #2

P: 26
Hi,

User will choose the date and time from the date time picker (javascript) and it is in yyyy/mm/dd hh:mm:ss
Every time i try to insert it, it will insert different date and time into the database.
I hope you can help me out

Regards,
Kencana
Feb 16 '08 #3

ronverdonk
Expert 2.5K+
P: 4,258
What is the correct date and time format of your MS SQL system?

You must adhere to that standard or you can setup the language of the user which connects to the DB, so that datetime is excepted in the language you have set up.

Ronald
Feb 16 '08 #4

P: 26
Hi,

i realized that the datetime format in mssql is dd/mm/yyyy hh:mm:ss am/pm
so I changed the input date time format and it still gave me no luck. it keep inserting 1/01/1900. Also, i tried to insert the date time value into the database manually by entering 17/02/2008 and it is accepted.
Any idea on how to solve this?

Thank you

Regards,
Kencana
Feb 16 '08 #5

ronverdonk
Expert 2.5K+
P: 4,258
Then you must have an error in your input format of the date (time) in your code. Show the code for that particular INSERT. And do not forget to enclose it within the appropriate code tags!

Ronald
Feb 16 '08 #6

P: 26
hi,

the following are my inserting code:

[PHP]
$content = str_replace("'", "''",$_POST['content']);
$startDate = "17/02/2008 12:00:00 AM";
$endDate = "17/02/2008 12:00:00 PM";

$insertStatement = "INSERT ANNOUNCEMENT (content,startdate,enddate,dateupdated) VALUES('" . $content . "', $startDate,$endDate,getdate())";
if (!mssql_query($insertStatement,$dbhandle))
{
echo "Failed due to ".mssql_error();
die('Error: ' . mssql_error());
}
else
{
echo "success";
}

mssql_close($dbhandle);
[/PHP]

regards,
Kencana
Feb 17 '08 #7

P: 26
Hi All,

anybody has any idea on how to insert string date into mssql database?

Thank you

Regards,
Kencana Kesuma
Feb 19 '08 #8

TheServant
Expert 100+
P: 1,168
How about justs storing a time stamp (as an INT) in the data base and convert back to a date when you need to display it?
Feb 19 '08 #9

P: 26
Hi,

Thanks for your reply, can you explain further on what you mean by the method you mentioned?

Thank you

Regards,
Kencana Kesuma
Feb 20 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.