Solved

Array type DATE toString formated

Posted on 2011-09-19
5
210 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
  • 3
  • 2
5 Comments
 
LVL 29

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 29

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 29

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Granting full access permission allows users to access mailboxes present in their database. By giving full access permission one can open and read the content of any mailbox but cannot send emails from that mailbox.
Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
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: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now