none
problem in value DateTimePicker when difference between date format in PC's ? RRS feed

  • Question

  • I have group pc's

    1. same pc's date format = dd/mm/yyyy
    2. another pc's date format = mm/dd/yyyy
    3. I'm use DateTimePicker format = dd/mm/yyyy

    when insert value date use vb.net and column type is date (only on pc's date format = mm/dd/yyyy)  show error :

    my code:

    cmd.Parameters.AddWithValue("@dateP", DateTimePicker1.Text)

    how to Fix ?
    • Edited by srajmuneer Sunday, May 21, 2017 5:00 PM
    Sunday, May 21, 2017 4:59 PM

Answers

  • Hi

    Try

    DateTimePicker1.Value

    instead of

    DateTimePicker1.Text


    Regards Les, Livingston, Scotland

    • Proposed as answer by Cor Ligthert Sunday, May 21, 2017 5:53 PM
    • Marked as answer by srajmuneer Sunday, May 21, 2017 6:29 PM
    Sunday, May 21, 2017 5:06 PM
  • if DateTimePicker1 format = dd/mm/yyyy and PC's date format = mm/dd/yyyy , How to format column date after insert in column (dateP) ?

    I don't know who you're talking to and I'm not a database guy, but understand this please:

    If you use the .Value from the control, you have a valid DateTime object. I know it's valid because you couldn't otherwise have gotten it from the DateTimePicker control.

    Once you have a valid DateTime (the .Value of the control), you can display it any way you want; the *real* data is still valid, no matter how it's displayed.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    • Marked as answer by srajmuneer Sunday, May 21, 2017 6:29 PM
    Sunday, May 21, 2017 6:23 PM

All replies

  • Hi

    Try

    DateTimePicker1.Value

    instead of

    DateTimePicker1.Text


    Regards Les, Livingston, Scotland

    • Proposed as answer by Cor Ligthert Sunday, May 21, 2017 5:53 PM
    • Marked as answer by srajmuneer Sunday, May 21, 2017 6:29 PM
    Sunday, May 21, 2017 5:06 PM
  • thanks leshay ,

    1. why difference between DateTimePicker1.Value or DateTimePicker1.Text
    2. can get Fixed value date (DateTimePicker1.Value) format = dd/mm/yyyy if :
    • pc's date format = dd/mm/yyyy

    OR

    • pc's date format = mm/dd/yyyy

    • Edited by srajmuneer Sunday, May 21, 2017 5:26 PM
    Sunday, May 21, 2017 5:25 PM
  • thanks leshay ,

    1. why difference between DateTimePicker1.Value or DateTimePicker1.Text
    2. can get Fixed value date (DateTimePicker1.Value) format = dd/mm/yyyy if :
    • pc's date format = dd/mm/yyyy

    OR

    • pc's date format = mm/dd/yyyy

    The .Value is an instance of the DateTime structure but the .Text is just a string representation of it.

    The display - by default - depends on the culture but you can change that using the CustomFormat property:

    https://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker.customformat(v=vs.110).aspx


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Sunday, May 21, 2017 5:33 PM
  • if DateTimePicker1 format = dd/mm/yyyy and PC's date format = mm/dd/yyyy , How to format column date after insert in column (dateP) ?
    Sunday, May 21, 2017 6:19 PM
  • if DateTimePicker1 format = dd/mm/yyyy and PC's date format = mm/dd/yyyy , How to format column date after insert in column (dateP) ?

    I don't know who you're talking to and I'm not a database guy, but understand this please:

    If you use the .Value from the control, you have a valid DateTime object. I know it's valid because you couldn't otherwise have gotten it from the DateTimePicker control.

    Once you have a valid DateTime (the .Value of the control), you can display it any way you want; the *real* data is still valid, no matter how it's displayed.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    • Marked as answer by srajmuneer Sunday, May 21, 2017 6:29 PM
    Sunday, May 21, 2017 6:23 PM