Results 1 to 8 of 8

Thread: [RESOLVED] [2005] How to display Date and/or Time ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Resolved [RESOLVED] [2005] How to display Date and/or Time ?

    I have Textbox1 on my form which is bound to a recordset and in which i want to display Date and/or Time in a custom format.

    How do i do this if i want the textbox1 to show this: 31/12/07, 22:50 ?

  2. #2
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: [2005] How to display Date and/or Time ?

    How is the value stored in the database? as a date or as a string?
    Do you retrieve the time and the date in the columns or in different columns?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] How to display Date and/or Time ?

    value is stored from the datetimepicker control as date in the database. I want to retrieve them to one column but it would be great if you tell me how to do it in different colums.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] How to display Date and/or Time ?

    You should use a DateTimePicker on your form if you want the user to be able to edit the value. If you jut want to display the value then you can use the ToString method of the DateTime type, e.g.
    vb.net Code:
    1. myDateTimeString = CDate(myDataRow("StartTime")).ToString("d/MM/yy, HH:mm")
    Just note that it is generally a bad idea to force a specific date/time format on the user without a very good reason. The user sets their preferred date/time format in Windows Regional Settings and you should do them the courtesy of using those settings. That way every user will see the date and time in the format that they expect. There can be no ambiguity that way. For instance, if you show the user the date as "1/02/07" then an American would assume that that is January 2, while you actually mean February 1. If a user has told Windows that they want things a certain way then you should respect that unless you have a very good reason to do otherwise, and then make sure that the user is aware of your decision so that they don't make incorrect assumptions about the values they are seeing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] How to display Date and/or Time ?

    Thank You for the suggestion Mr.JM but in our country we use dd/mm/yy only !

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] How to display Date and/or Time ?

    Quote Originally Posted by LuxCoder
    Thank You for the suggestion Mr.JM but in our country we use dd/mm/yy only !
    That's irrelevant. In my country (Australia) we use dd/MM/yyyy as standard but that should make no difference. If your application ends up overseas or someone from overseas uses it in your country and wants to set up their machine to use the regional settings they're used to they should be able to. If I travel to the US I'm going to leave the regional settings on my laptop set to Australian. I'd be p*ssed off if some local software uses US date formats without telling me and I end up doing something or going somewhere on the wrong date. You should respect the choices made by each user, particularly if it doesn't take any more effort on your part to do so.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [RESOLVED] [2005] How to display Date and/or Time ?

    hmm thats true !

    Mr. JM, do you make projects on freelance basis also ? If you do then will you make my project in return of some fees ! I am so much impressed by your replies to my questions in this site, that i completely trust you for that purpose !

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [2005] How to display Date and/or Time ?

    Thank you for the vote of confidence but my time is fully committed at the moment.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width