Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Visual Studio C# Date Formats

Posted on 2010-01-12
7
Medium Priority
?
446 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
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month13 days, 5 hours left to enroll

578 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