Link to home
Start Free TrialLog in
Avatar of ANINDYA
ANINDYAFlag for India

asked on

DatetimePicker Problem C#

Experts,
I have qestion that is when I am selecting any date from the datetimepicker as in this form (return date) then it is taking the date and also the time. (Please see the image attached)
I am doing in this manner
DateTime DateofReturn;
                DateofReturn = dateTimePicker_ReturningDate.Value;
And the query I am using for Save option is

string query = "insert into Table_Borrow(MemberID,Film_ID,NameofItem,DateofReturn,Status) values(@parameter1,@parameter2,@parameter3,@parameter4,'" + b.ToString() + "')";

May I know what I have to do so that only the date as selected from the datetimepicker should get saved not time (that is 7A.M. should not get saved)

Thanking you,
Anindya
error.jpg
ASKER CERTIFIED SOLUTION
Avatar of Om Prakash
Om Prakash
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try:
DateofReturn = dateTimePicker_ReturningDate.Value.Date

Open in new window

sorry,

Same answer as: mas_oz2003
Avatar of ANINDYA

ASKER

Expert Om Prakash ji
here I have used your code and I am not getting where I am wrong that I am not getting the proper thing that is the time is still coming .
please see the images attached.
Thanking you
Anindya
1.jpg
error.jpg
Avatar of ANINDYA

ASKER

Expert mas_OZ2003
Please see the attached images.
I am getting the date but the time is also coming in
the format as
00:00:00
Sir how to ommit it.
Thanking you
Anindya
oz.jpg
oz2.jpg
Try this.
DateofReturn = dateTimePicker_ReturningDate.Value.Date
Avatar of ANINDYA

ASKER

Expert saravanansofts
Itried the same
but the problem is it is taking date followed by 00:00:00
why this is coming ?
How to ommit it?
Thanking you
anindya
What version of Sql are you using ?

only in 2008 can you have a date only field, prior to this all date fields in sql are date and time .... which means if you put a date without a time sql (and c#) will put a time of 00:00:00in. This is not avoidable.

if you are using sql 2008 then change your data time from datetime/ smalldatetime to date
Avatar of ANINDYA

ASKER

experts
I am using sql server 2005
Avatar of ANINDYA

ASKER

Expert zadeveloper:
I am using sql server 2005.
Thanking you
Anindya
Avatar of ANINDYA

ASKER

The datatype is DateTime which I am using here for the returndate attribute.
Thanking you
try this one

I Think you should use varchar(12) instead of datetime. that will solve your Problem. while saving just save your string as '2010/07/09'.

Best Regards
Waqar Hussain Laghari
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ANINDYA

ASKER

Master zadeveloper
I have seen that your 1st reply was same as that of  Expert  mas_OZ2003.
So I am sorry that I had not addressed you .
Sir if you see the reply which I had given after you and  mas_OZ2003 suggested me the solution.
If you kindly see the two images attached at that time then I think you will get the clear picture of what is happening .
Sir the problem is I am saving the value of the date and the date is getting saved with date correctly but after using the
dateTimePicker_ReturningDate.Value.Date
I am getting date as well the 00:00:00 also .
Please see the images attached for clarification.
I want in the table only the date should get saved not date and 00:00:00
Thanking you
Anindya
Avatar of ANINDYA

ASKER

Expert  Waqar Hussain Laghari
I am not going to change the datatype as it may cause some problem for me in other sections .
Thanking you
Anindya
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ANINDYA

ASKER

Experts
thanks for answering me .
Although my problem is not solved but I think it is better to keep with the previous state.
Thanking you,
Anindya Chatterjee
Bangalore
Hi! Anindya

It will be suitable for you IF you will take date as varchar(8) etc. as suggested by waqarlaghar It will help you to proceed easily in the future. I know tables have some dependencies. But its better to remove a problem rather than to use a local way. ;)

So, if possible try an easier approach.
You Can Use this Code.. :  dateTmiePicker.Value.ToShortDateString();
You Can Use this Code.. :  dateTmiePicker.Value.ToShortDateString();