Solved

Array type DATE toString formated

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
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: …
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…

730 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