Solved

Format Textbox to Date

Posted on 2013-06-03
4
451 Views
Last Modified: 2013-06-03
Hi:

I have concatenated the values from 3 text boxes to 1 to be placed within the textbox OOCRun1.

However, I need to format the textbox to date but I am not getting through.

OOCRun1.Text = Day1.Text + CycleNo1.Text + PayYear1.Text
OOCRun1.Text = Convert.ToDateTime(OOCRun1.Text).ToString("MM/DD/YYYY")

Please advise.
0
Comment
Question by:ernie_shah
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 39216728
try this,
        
OOCRun1.Text = Day1.Text + CycleNo1.Text + PayYear1.Text
OOCRun1.Text = DateTime.ParseExact(OOCRun1.Text, "dd/MM/yyyy", Nothing).ToString("MM/dd/yyyy")

Open in new window

0
 

Author Comment

by:ernie_shah
ID: 39216806
The error message " String was not recognized as a valid DateTime" is raised

Example of the data in the fields:

Day1 - 16
CycleNo1 - 4
PayYear1 - 2013

OOCRUN1 -1642013

I need OOCRun1 formatted to 4/16/2013
0
 
LVL 18

Accepted Solution

by:
Rajar Ahmed earned 500 total points
ID: 39216866
Try this ,
        
OOCRun1.Text = Day1.Text & "/" & CycleNo1.Text & "/" & PayYear1.Text
OOCRun1.Text = DateTime.ParseExact(OOCRun1.Text, "dd/M/yyyy", Nothing).ToString("M/dd/yyyy")

Open in new window

0
 

Author Comment

by:ernie_shah
ID: 39216880
Excellent thanks,

Works like a charm.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question