Solved

Format Textbox to Date

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Export import database 4 42
How to add <appSettings> to the webconfig file 2 20
IIS Authorization for Web Service 2 21
Need a starter for ETL protocol? 4 42
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now