Solved

Array type DATE toString formated

Posted on 2011-09-19
5
215 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 125 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

Technology Partners: 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

Read this checklist to learn more about the 15 things you should never include in an email signature.
Mailbox Overload?
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

687 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