[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

unable to update datetimepicker date values sqlserver database.

Posted on 2009-02-11
7
Medium Priority
?
561 Views
Last Modified: 2012-05-06
Hi,
I tried to update one table with :
update StatusOfFittings set FittingCompletedDate = '05-02-2009 PM 03:13:50' where FittingName = 'WBSTDWTzxcvbn'

Here FittingCompletedDate is the datetime Datatype.
I am using DatetimePicker control in C#-winforms front end.
ditrectky i took the date like: FittingCompletedDate = 'datetimepicker.value.ToString()'
I got exception: "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value."

One of Expert given this comment before:

pratima_mcs:try something like this

 FittingCompletedDate = 'datetimepicker.value.ToString("yyyy-MM-dd hh:mm:ss")

I changed like this, but I able to update only time, changes of am to pm .
Means..as per time: '05-02-2009 PM 03:13:50'  but it updates '05-02-2009 AM 03:13:50'  like this.

Plz help on this. I want to update exact timing into the sql database.

Thanx.
0
Comment
Question by:raghu_apps
7 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 23619735
I am not getting =teh exact problem tell me
if you try like this directly will it work ?

update StatusOfFittings set FittingCompletedDate = '06-03-2009 PM 03:13:50' where FittingName = 'WBSTDWTzxcvbn'
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 23619738
change the following
FittingCompletedDate = datetimepicker.value.ToString("yyyy-MM-dd HH:mm:ss")
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 23619747
your codes is
FittingCompletedDate = datetimepicker.value.ToString("yyyy-MM-dd hh:mm:ss")

and mine is
FittingCompletedDate = datetimepicker.value.ToString("yyyy-MM-dd HH:mm:ss")

i have changed hh to HH which takes 24 hour clock and not 12 hour clock
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:raghu_apps
ID: 23619826
Hi,
That is Correct. But I need to update as 12-hr format including am and pm.

Here exact date and time was updated instead am to pm or pm to am (means it updated 12-hours back).

I want to update exact date time as per our system time. It is mandatory for me.. I am using GMT+5:30 time.
plz advice.

thanx.
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 23619854
u can format that once in the application. in sql it will store in 24 hr format
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 23619855
or else u need to store it as string in the DB which is not advisable
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 1500 total points
ID: 23620074
sql always stores it in 24 hour format and when you return the value to the place where you want to use you can format the values then

you can use the following
Show date in 12H format with AM/PM as: "Friday 13 August 01:00:13 PM"
date.DayOfWeek + " " + date.Day + " " + date.ToString("MMMM") + " " + date.ToString("hh:PM:mm:ss:tt")
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question