elmonko
elmonko

Reputation: 685

Change date format in code only

I've a code that simply creates a folder in a directory and gives it a name based on the values of a datetimepicker and a text box.

The date picker is displayed on the form as "16 October 2013" (how I want to keep it) but when I generate the file name I would lime the date to read in the format "161013"

The code I'm using is below if that helps

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)    Handles Button1.Click

    Dim lMailbox As String


    lMailbox = t2.Text & "-" & d1.Text

    ' Check if folder exists, if not: create it
    If Not Directory.Exists(nMailbox & lMailbox) Then
        Directory.CreateDirectory(nMailbox & lMailbox)

        ' Folder created message
        MessageBox.Show("Mailbox created!", "Lynx Control Panel", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else
        ' Folder already exists
        MessageBox.Show("Mailbox already exists!", "Lynx Control Panel", MessageBoxButtons.OK, MessageBoxIcon.Stop)
    End If
End Sub

The nMailbox & lMailbox are declared at the top of the code page

d1 is the name of the datepicker

I'm very new to VB.net and would appreciate any help

Thanks

Upvotes: 1

Views: 263

Answers (1)

try this:

lMailbox = t2.Text & "-" & d1.Value.ToString("ddMMyy")

The format options are the same as for DateTime string formatting. Use Value of the DTP rather than the Text which is formatted otherwise/

Upvotes: 2

Related Questions