Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Itext sharp date time With my code result is 16.04.2020
That is ok...

If I have 2 date in table...i cant solve
Second date is 16.04.2020 00:00:00
Thank you

What I have tried:

C#
//Adding DataRow
            foreach (DataGridViewRow row in ListDataGridView.Rows)
            {
                int c = 0;
                foreach (DataGridViewCell cell in row.Cells)
                {
                    if (c == 2)
                    {
                        PdfPCell cell2 = new PdfPCell(new Phrase(cell.Value.ToString().Split(' ')[0], calibri));
                        pdfTable.AddCell(cell2);
                    }
                    else
                    {
                        PdfPCell cell2 = new PdfPCell(new Phrase(cell.Value.ToString(), calibri));
                    cell2.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell2.VerticalAlignment = Element.ALIGN_CENTER;
                    pdfTable.AddCell(cell2);
                    }
                    c++;
                }
            }
Posted
Updated 16-Apr-20 7:09am
v2

1 solution

You need to use basic string formatting:
C#
System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.InvariantCulture;

DateTime d = DateTime.ParseExact("16.04.2020 00:00:00", "dd.MM.yyyy HH:mm:ss", ci);

Console.WriteLine(d.ToString());
//produces: 16.04.2020 00:00:00
Console.WriteLine(d.ToString("dd.MM.yyyy"));
//produces: 16.04.2020


For further details, please see:
Standard numeric format strings | Microsoft Docs[^]
Custom numeric format strings | Microsoft Docs[^]
 
Share this answer
 
v2
Comments
Goran Bibic 16-Apr-20 12:57pm    
I need that fo itext sharp
Maciej Los 16-Apr-20 14:05pm    
My best guess is:
PdfPCell cell2 = new PdfPCell(new Phrase(cell.Value.ToString().Split(' ')[0], calibri));
PdfPCell cell2 = new PdfPCell(new Phrase(cell.Value.ToString("dd.MM.yyyy"), calibri));

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900