locked
How can make The DateTimePicker ???? RRS feed

  • Question

  • I need To know ,,,,,,,,,,,,,,,,,,, i have database that recieves Date from DatetimePicker control but when i check my databse field i find its okay its put the date rightly but with the time aslo ,,, is any possible way to make it insert Date only ,, if as long or short type ,,,,,,,,,,,,,,,, because i want that helping me later when make query report depened on some date and maybe time with confuse my query or make it harder ,,,,,,,,, i just want simple Date only if with this format 1 January 2009 or 1/1/2009 .,...... i try to do it with custom Format and make the Date only as i want but when i run my form and open the dropdown menu to show up the DateTimepicker and choiced some day i find that the dropdown box still have the same valued i left on the Formate with Custom property

    okay thank you anyway
    Saturday, May 16, 2009 2:27 AM

Answers

  • string date = InformDateTimePicker.Value.Date;


    Thanks,
    A.m.a.L
    .Net Goodies
    Remember to click "mark as answered" when you get a correct reply to your question
    • Marked as answer by HESHAM HEMDAN Saturday, May 16, 2009 6:15 PM
    Saturday, May 16, 2009 5:30 PM
  • as you can see, you are passing only Date to the database, but database is storing date with time.

    On option is while reading you will be getting the datetime object.
    To the end user just give datetimeobject.Date.



    Thanks,
    A.m.a.L
    .Net Goodies
    Remember to click "mark as answered" when you get a correct reply to your question
    • Marked as answer by HESHAM HEMDAN Saturday, May 16, 2009 6:15 PM
    Saturday, May 16, 2009 6:09 PM
  • Since your database column type is datetime, it will store date with time.


    Thanks,
    A.m.a.L
    .Net Goodies
    Remember to click "mark as answered" when you get a correct reply to your question
    • Marked as answer by HESHAM HEMDAN Saturday, May 16, 2009 6:41 PM
    Saturday, May 16, 2009 6:16 PM

All replies

  • DateTimePicker.Value will return a datetime object.
    while inserting to database you can use

    DateTime.Date

    http://msdn.microsoft.com/en-us/library/system.datetime.date.aspx



    Thanks,
    A.m.a.L
    .Net Goodies
    Remember to click "mark as answered" when you get a correct reply to your question
    Saturday, May 16, 2009 6:04 AM
  • Look ,,, i try it like that

    // making the DateTimepicker object Date without Time

     

    DateTime informdate1 = new DateTime(InformDateTimePicker.Value);

     

    DateTime Dateonly = informdate1.Date;

     

    string date = Dateonly.ToString();



    but this gives me error ........................ how can i get the value of the DateTimePicker and cut the Time from it and then give it to the Parameters who will insert it to the Database .... i hope you understand me

    look ,,,,, make is simple am just beginner and i read the msdn help that you sent me and i understand it but i cant do it with datetimepicker ,,, the point is how to cut the Time from The DateTimePicker ,,,,,,,,,,

    Saturday, May 16, 2009 3:21 PM
  • string date = InformDateTimePicker.Value.Date;


    Thanks,
    A.m.a.L
    .Net Goodies
    Remember to click "mark as answered" when you get a correct reply to your question
    • Marked as answer by HESHAM HEMDAN Saturday, May 16, 2009 6:15 PM
    Saturday, May 16, 2009 5:30 PM
  • Look


    DateTime

    date = InformDateTimePicker.Value.Date;

     

    cmd.Parameters.Add(

    "@InformDate", SqlDbType.NVarChar, 50);

    cmd.Parameters[

    "@InformDate"].Value = date.ToString();


    its work and insert the Date but also with the time


    i need you to tell me

    i must make the Column of InformDate on Database  DateTime difinition or what

    and also i make it string and gives me the same and i maked it DateTime and gives me the same its also shows the Time in The DateBase Table

    Saturday, May 16, 2009 6:03 PM
  • as you can see, you are passing only Date to the database, but database is storing date with time.

    On option is while reading you will be getting the datetime object.
    To the end user just give datetimeobject.Date.



    Thanks,
    A.m.a.L
    .Net Goodies
    Remember to click "mark as answered" when you get a correct reply to your question
    • Marked as answer by HESHAM HEMDAN Saturday, May 16, 2009 6:15 PM
    Saturday, May 16, 2009 6:09 PM
  • i also tried that

    DateTime

    date = InformDateTimePicker.Value.Date;

     

    DateTime date2 = date.Date;

     

    cmd.Parameters.Add(

    "@InformDate", SqlDbType.DateTime);

    cmd.Parameters[

    "@InformDate"].Value = date2;


    look ,,, after i make the inserting and search this field and bind it on my Gridview its succeed and shows me Date only but when am open my Database Table and see the inserted information i find its make its Full DateTime ,,,,,,,,,, Date and Time still on database Table ,,,,,

    Saturday, May 16, 2009 6:10 PM
  • okay thats good ,,, understand ,,,,,,,,,,,, its good for enduser now but there important thing maybe i want make a report query Customers by Inform Date ,,, is it will be possible to qury by some date and the query searcher will ignore the Time or what i have to do ,,, i just want make sure that this Date inserting make easy to me the finally tasks of searching between some dates ,,, i dont want time is make problem because who will insert this data maybe dont care about wich time at day its have been inserted ,,, okay that my last concern


    i think you do alot of helping with me and i hope you complete it thank you anyway
    Saturday, May 16, 2009 6:15 PM
  • Since your database column type is datetime, it will store date with time.


    Thanks,
    A.m.a.L
    .Net Goodies
    Remember to click "mark as answered" when you get a correct reply to your question
    • Marked as answer by HESHAM HEMDAN Saturday, May 16, 2009 6:41 PM
    Saturday, May 16, 2009 6:16 PM
  • okay ,, thank you anway

    Saturday, May 16, 2009 6:36 PM
  • ok just wanna make sure about something

    i will leave it DateTime okay and Save the Database Table Date with Time

    when am query some Date ,,,,,,,,,,,,, i must specific the Time also with Date to Bring me some Date exactly or between 2 dates entry ,,,,,,,,,,,

    Saturday, May 16, 2009 6:41 PM
  • No need to specify time.

    You can pass the two date value.


    Thanks,
    A.m.a.L
    .Net Goodies
    Remember to click "mark as answered" when you get a correct reply to your question
    Saturday, May 16, 2009 6:42 PM