7 Replies - 424 Views - Last Post: 11 April 2013 - 03:12 PM Rate Topic: -----

#1 itzmePoulami  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 12-March 13

convert mm dd yyyy to words in vb.net

Posted 10 April 2013 - 05:00 AM

I want 4/10/2013 to be visible as 4th April 2013.. is it possible.. help me out..
Is This A Good Question/Topic? 0
  • +

Replies To: convert mm dd yyyy to words in vb.net

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6035
  • View blog
  • Posts: 23,418
  • Joined: 23-August 08

Re: convert mm dd yyyy to words in vb.net

Posted 10 April 2013 - 05:14 AM

http://msdn.microsof...y/w2sa9yss.aspx

http://msdn.microsof...y/zdtaw1bw.aspx

http://msdn.microsof...y/8kb3ddd4.aspx
Was This Post Helpful? 0
  • +
  • -

#3 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: convert mm dd yyyy to words in vb.net

Posted 10 April 2013 - 05:45 AM

View PostitzmePoulami, on 10 April 2013 - 06:00 AM, said:

I want 4/10/2013 to be visible as 4th April 2013.. is it possible.. help me out..

JackOfAllTrades has given you some good links to the documentation for formatting Date Strings, but I notice you used "4th" as part of your example, and that isn't a standard format. So my question to you would be "Do you want to use the English ordinal abbreviations, like 1st, 2nd, 3rd, 4th, 5th, etc. or are you just looking for making the month display as words?"
Was This Post Helpful? 0
  • +
  • -

#4 itzmePoulami  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 12-March 13

Re: convert mm dd yyyy to words in vb.net

Posted 10 April 2013 - 05:54 AM

thanks a lot..!!! I did it.. :)

View Postlar3ry, on 10 April 2013 - 05:45 AM, said:

View PostitzmePoulami, on 10 April 2013 - 06:00 AM, said:

I want 4/10/2013 to be visible as 4th April 2013.. is it possible.. help me out..

JackOfAllTrades has given you some good links to the documentation for formatting Date Strings, but I notice you used "4th" as part of your example, and that isn't a standard format. So my question to you would be "Do you want to use the English ordinal abbreviations, like 1st, 2nd, 3rd, 4th, 5th, etc. or are you just looking for making the month display as words?"




I'm quite happy with the standard format.. but if you can help me on "4th" part I'd be grateful...
Was This Post Helpful? 0
  • +
  • -

#5 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 199
  • View blog
  • Posts: 696
  • Joined: 01-February 13

Re: convert mm dd yyyy to words in vb.net

Posted 10 April 2013 - 06:35 AM

Hi,
I don`t know if you have your date in a string or what but, here is one way you could add the (th, st, nd, or rd) to the end of the day number.
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim mydate As String = "4/12/2013"
        Dim dd As String = mydate.Substring(mydate.IndexOf("/") + 1)
        dd = dd.Remove(dd.LastIndexOf("/"))
        Dim de() As String = {"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"}

        If CInt(dd) > 10 And CInt(dd) < 14 Then
            Label1.Text = dd & "th"
        Else
            Label1.Text = dd & de(CInt(dd.Substring(dd.Length - 1)))
        End If
    End Sub


Edit : I was using the month not day. :whistling:/>/>

If you are displaying the current day then you can shorten the above to this
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dd As String = Now.Day.ToString
        Dim de() As String = {"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"}

        If CInt(dd) > 10 And CInt(dd) < 14 Then
            Label1.Text = dd & "th"
        Else
            Label1.Text = dd & de(CInt(dd.Substring(dd.Length - 1)))
        End If
    End Sub


This post has been edited by IronRazer: 10 April 2013 - 08:02 AM

Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: convert mm dd yyyy to words in vb.net

Posted 10 April 2013 - 07:09 AM

IronRazer, you might try that code with a date of 4/11/2013, 4/12/2013 etc... ;)
Was This Post Helpful? 1
  • +
  • -

#7 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 199
  • View blog
  • Posts: 696
  • Joined: 01-February 13

Re: convert mm dd yyyy to words in vb.net

Posted 10 April 2013 - 07:35 AM

View PostCharlieMay, on 10 April 2013 - 09:09 AM, said:

IronRazer, you might try that code with a date of 4/11/2013, 4/12/2013 etc... ;)/>/>/>

Ahh..yes i see what you mean. "11st" and "12nd" is not rite. Guess i should have seen that. :blush:/>/>

I Edited and fixed the above post. :rolleyes2:

This post has been edited by IronRazer: 10 April 2013 - 08:04 AM

Was This Post Helpful? 0
  • +
  • -

#8 Stefone  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-April 13

Re: convert mm dd yyyy to words in vb.net

Posted 11 April 2013 - 03:12 PM

View PostitzmePoulami, on 10 April 2013 - 05:00 AM, said:

I want 4/10/2013 to be visible as 4th April 2013.. is it possible.. help me out..


Dim DateToday as string
Dim DateNow as string

DateToday = DateTime.Now
DateNow = (DateToday.ToString("D"))

DateLabel.Text = DateNow

View PostStefone, on 11 April 2013 - 03:09 PM, said:

View PostitzmePoulami, on 10 April 2013 - 05:00 AM, said:

I want 4/10/2013 to be visible as 4th April 2013.. is it possible.. help me out..


Dim DateToday as string
Dim DateNow as string

DateToday = DateTime.Now
DateNow = (DateToday.ToString("D"))

DateLabel.Text = DateNow


Sorry made a mistake

Dim DateToday As DateTime
Dim DateNow As String

DateToday = DateTime.Now
DateNow = (DateToday.ToString("D"))
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1