Date Formatting

How to properly format date

Page 1 of 1

3 Replies - 1832 Views - Last Post: 09 November 2007 - 08:58 PM Rate Topic: -----

#1 libby50  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 08-November 07

Date Formatting

Post icon  Posted 08 November 2007 - 03:36 PM

Private Sub formatButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles formatButton1.Click
' changes a year from "yyyy" to "yy"
Dim newDate As String
Format(Now, "mmmm dd, yyyy")
newDate = dateTextBox.Text
OutPut.Text = Format(Now, "mm, dd, yy")


I am trying to format a date for example I need

January 20, 2008 .....to format to this 01/20/08

Is This A Good Question/Topic? 0
  • +

Replies To: Date Formatting

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Date Formatting

Posted 08 November 2007 - 04:37 PM

To accomplish this use the ToString with your format, like so

Private Sub formatButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles formatButton1.Click
' changes a year from "yyyy" to "yy"
Dim newDate As DateTime = Now()
OutPut.Text = newDate.ToString("dd/MM/yy")



If the value is coming from a textbox, make sure you cast it to a date first otherwise you'll have unhandled exceptions

Dim newDate As DateTime = CType(TextBox1.Text,DateTime)
OutPut.Text = newDate.ToString("dd/MM/yy")



Hope this helps :)

This post has been edited by PsychoCoder: 08 November 2007 - 04:38 PM

Was This Post Helpful? 0
  • +
  • -

#3 muddasir  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 114
  • Joined: 14-January 07

Re: Date Formatting

Posted 09 November 2007 - 08:52 AM

if you want to change your system date format view my
snippet "change system date format " at Visual Basic Snippets


View Postlibby50, on 8 Nov, 2007 - 03:36 PM, said:

Private Sub formatButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles formatButton1.Click
' changes a year from "yyyy" to "yy"
Dim newDate As String
Format(Now, "mmmm dd, yyyy")
newDate = dateTextBox.Text
OutPut.Text = Format(Now, "mm, dd, yy")


I am trying to format a date for example I need

January 20, 2008 .....to format to this 01/20/08

Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Date Formatting

Posted 09 November 2007 - 08:58 PM

@muddasir, he doesn't have to do all that with the Win32 API's to just change the format the date is displayed in, he just needs to just do what I showed him to change the way the date is displayed :)

Your is a nice snippet, but a bit overkill for what he was wanting to accomplish :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1