Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Date time remove time from pdf report

if (c == 2)
my report is

date payment
01.01.2019 01.01.2019 00:00:00

I try to add this

<pre>  if (c == 2) && (c == 3)


my report is

date payment
01.01.2019 00:00:00 01.01.2019 00:00:00



I try to add d (like on example code)

<pre>
<pre>  if (c == 2) && (d == 3)


my report is

date payment
01.01.2019 00:00:00 01.01.2019 00:00:00


Some help please?

What I have tried:

//Adding DataRow
           foreach (DataGridViewRow row in AnalitickaKarticaPartneraDataGridView.Rows)
           {

               int c = 0;
               int d = 0;
               foreach (DataGridViewCell cell in row.Cells)
               {
                   if (c == 2 && d == 3)
                   {
                       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));
                       pdfTable.AddCell(cell2);
                   }
                   c++;
                   d++;
               }

           }
Posted
Updated 21-Jul-19 23:48pm

1 solution

This is quite nonsense:
C#
if (c == 2) && (c == 3)
would never be true: a variable cannot have two values at the same time.
C#
if (c == 2) && (d == 3)
would never be true either: both variables are declared at the same time and incremented at the same time. Unless you did not show all of the code, there is no chance one can have a value which differs from the other.

Moreover, none of this is related to DateTime display-format.

Here's the skeleton to retrieve and modify a datetime's format:
C#
string value = "01.01.2019 00:00:00";
DateTime dt;
string formattedDate;
if (DateTime.TryParseExact(
   value,
   "dd.MM.yyyy HH:mm:ss",
   CultureInfo.CurrentCulture,
   DateTimeStyles.None,
   out dt
) {
   formattedDate = dt.ToString("dd.MM.yyyy");
}
else
{
   // Datetime could not be parsed. Check the format string and actual input.
}
 
Share this answer
 
Comments
Goran Bibic 22-Jul-19 5:54am    
How to implement this in my code?
phil.o 22-Jul-19 6:05am    
I can't answer that precisely; no one can. We do not have access to the source code, we do not have access to the contents of the grid view. What I provided here is a generic way to handle datetimes, that is, work with real DateTime structures, not on string representations of them.
So it's now up to you; you can use the debugger to have more informations about the objects you are dealing with.
Goran Bibic 22-Jul-19 6:36am    
Need to implement you solution here

//Adding DataRow
foreach (DataGridViewRow row in AnalitickaKarticaPartneraDataGridView.Rows)
{

int c = 0;
int d = 0;
foreach (DataGridViewCell cell in row.Cells)
{
if (c == 2 && d == 3)
{
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));
pdfTable.AddCell(cell2);
}
c++;
d++;
}

}

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