Solved

Format Textbox to Date

Posted on 2013-06-03
4
458 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 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