?
Solved

Visual Studio C# Date Formats

Posted on 2010-01-12
7
Medium Priority
?
445 Views
Last Modified: 2012-05-08
I have selected data and have placed in on the form. I cannot quite get the syntax for the date format correct. I want it to be short fomat MM/DD/YY. I have guides for the various formats but I cannot quite get the syntax correct for VS 2008 C#.
 
Snippet.txt
0
Comment
Question by:rwheeler23
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 26296116
use DateTimeObject.ToShortDateString()
0
 
LVL 21

Accepted Solution

by:
silemone earned 2000 total points
ID: 26296171
so basically do this:


DateTime dt = new DateTime.Now;

txtBox.text = dt.toShortDateString();

of course in your asp page, add a txtbox to with id txtBox...

if you're getting the date from somewhere

DateTime dt = new DateTime(strDate.Text.ToString().Trim());  // <-- strDate would be where y

txtBox.text = dt.toShortDateString();
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:p_davis
ID: 26296172
if you just wanted to know the string syntax it is

dateTimeObj.ToString("mm/dd/yy");
0
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 26296301
I prefer using the FormatDateTime method.

ie.  FormatDateTime(now, DateForat.ShortDate)
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 26297001
My advice: bookmark the page below. It contains a very good reference to data-time formatting (as well as formatting for numbers etc).

You may build any string you want. See the snippet. It gives, e.g., a string like:
13 Jan 2010,Wednesday, 09:06.

You may write month name in full, or, Wed instead Wednesday, etc. Very flexible. Try!

http://john-sheehan.com/blog/wp-content/uploads/msnet-formatting-strings.pdf

        private void button2_Click(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Now;

            MessageBox.Show(dt.ToString("d MMM yyyy, dddd, HH:mm"));
        }

Open in new window

0
 

Author Comment

by:rwheeler23
ID: 26298224
OK, i think my naivity is geTting in the way here. I execute the below SQL statement which is pulling the date from a field called DATE_OF_QUOTE_OEQH. This is a datetime field in SQL which I believe is getting converted to a text field in VS. So I think I have my command outs of sequence. If you could show me the correct sequence with actual commands I think I will be all set.

/* SQL Command ===============
qhCommand.CommandText = "select top 1 QUOTE_NUMBER_OEQH,SEQUENCE_NUMBER_OEQH,REVALIDATE_NUMB_OEQH,CUSTOMER_NUMBER_OEQH,SALES_AGENT_OEQH,DATE_OF_QUOTE_OEQH,CUSTOMER_NAME_OEQH,CUSTOMR_CONTACT_OEQH,CUSTOMER_PO_#_OEQH,AMRKCODE_OEQH from SOPLINES s1, CSTQUTHD s2 where s1.QUOTE_NUMBER_SOPL=s2.QUOTE_NUMBER_OEQH and s1.SEQUENCE_NUMBER_SOPL=s2.SEQUENCE_NUMBER_OEQH and s1.REVALIDATE_NUMBER_SOPL=s2.REVALIDATE_NUMB_OEQH AND s1.sopnumbe_sopl = '" + sopEntryWindow.SopNumber.Value +"'";
===============================================================================
this.txtDateOfQuote.DataBindings.Add("Text", QuoteHeaderDataSet.Tables["QuoteHeader"], "DATE_OF_QUOTE_OEQH");
            DateTime dt = new DateTime(this.txtDateOfQuote.Text.ToString().Trim());  
            this.txtDateOfQuote.text = dt.toShortDateString();
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

741 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