?
Solved

Array type DATE toString formated

Posted on 2011-09-19
5
Medium Priority
?
216 Views
Last Modified: 2012-05-12
Hi
I have the attcahed code.

Some of the array values is dates, but it is formated like this :
dd/mm/yyyy hh:mm:ss

I would like to get rid of the time section.
 
for (i = 0; i < array.Length - 1; i++)                    
                        {
                            sw.Write(array[i].ToString() + ";");
                        }

Open in new window

0
Comment
Question by:conceptdata
[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
  • 3
  • 2
5 Comments
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 36563740
The task is not quite clear.
Array elements are Date instances? Or strings? If they are dates - we can't talk about formatting. If strings - I can't see why you use

array(i.ToString()

What does it mean: "Some of the array values". Other values are not dates? Or date formatted strings?

Could you please make it more clear?
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 36563789
BTW, if an element has dd/mm/yyyy hh:mm:ss formatting - you just split the string into two using a space as a delimeter, and print the first string only (date part).

something like:


private void button2_Click(object sender, EventArgs e)
        {

            string dt = @"21/09/2011 23:14:04";
            string[] separator = {" "};
            string[] dtar = dt.Split(separator, StringSplitOptions.RemoveEmptyEntries);
            string datepart = dtar[0];
            MessageBox.Show(datepart);
        }

Open in new window

0
 

Author Comment

by:conceptdata
ID: 36565012
-> anarki_jimbel :
Your solution seems to be the thing i'm looking for.
But, the problem is that I have other format than dates in the array.

Ex. : String, String, Int, Real, Date, String, String

So is there a way to get the type and if the type is date, then use your solution ??
0
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 500 total points
ID: 36569710
OK, I have another example. It's quite self explanatory:
private void button2_Click(object sender, EventArgs e)
        {
            string a0 = "Hello";
            int a1 = 123;
            DateTime a2 = DateTime.Now;
            string a3 = "Hasta la vista";

            object[] a =new object[]{a0,a1,a2,a3};

            foreach (object o in a)
            {
                if (o is DateTime)
                {
                    DateTime dt = (DateTime)o;
                    MessageBox.Show(dt.ToShortDateString());
                }
            }
        }

Open in new window

0
 

Author Comment

by:conceptdata
ID: 36576412
Thats it... Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Suggested Courses

762 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