Solved

Array type DATE toString formated

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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
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: …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

791 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