We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

unable to update datetimepicker date values sqlserver database.

raghu_apps
raghu_apps asked
on
Medium Priority
590 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.
Comment
Watch Question

CERTIFIED EXPERT

Commented:
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'
Anurag ThakurTechnical Manager

Commented:
change the following
FittingCompletedDate = datetimepicker.value.ToString("yyyy-MM-dd HH:mm:ss")
Anurag ThakurTechnical Manager

Commented:
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

Author

Commented:
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.
CERTIFIED EXPERT

Commented:
u can format that once in the application. in sql it will store in 24 hr format
CERTIFIED EXPERT

Commented:
or else u need to store it as string in the DB which is not advisable
Technical Manager
Commented:
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")

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.