Hey Guys,

I have a Data Grid View which displays a few things from the database, one of the information being displayed is the Date,The date is set in Clarion and i want to change it so it gets changed to the date we see it as today.

I have a formula which can convert the to clarion date to todays date, but how do i display it in the grid view for all the rows.


Now todays date is 16/5/2011 (UK FORMAT)

Clarion Date is 01/01/1900

Clarion Days to this date is : 36161


To Calculate to clarion the formula is : 16/5/2011 - 01/01/1900 = 40678

40678 + 36161 = 76839


Now the result shown above is the format my GridView is being populated, so i want to change the numbers from 76839 to date format which will be todays date.

Can anyone help? as GridView will have many different Clarion Dates the formula will need applying to, but the main thing is to make sure one attribute in a gridview can be displayed differently.

Can someone please help thanks :)

Dani AI

Generated

Useful follow-up and a cleaner pattern to use with a GridView (C# examples, since the thread is tagged .NET/C#). has the right idea — the Clarion value is a day-count that needs converting to a DateTime before display. Do the conversion during data binding (so the GridView shows a formatted date, not the raw number).

A safe per-row approach is to convert in RowDataBound:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType != DataControlRowType.DataRow) return;

    object raw = DataBinder.Eval(e.Row.DataItem, "ClarionDays");
    if (raw == null || raw == DBNull.Value) return;

    if (!int.TryParse(raw.ToString(), out int clarionDays)) return;

    DateTime clarionEpoch = new DateTime(1900, 1, 1); // adjust if your Clarion base differs
    // If your data uses an extra offset, subtract it here: clarionDays -= myOffset;
    DateTime converted = clarionEpoch.AddDays(clarionDays);

    // either set a cell text or find a Literal/Label in a TemplateField
    e.Row.Cells[/*columnIndex*/].Text = converted.ToString("dd/MM/yyyy"); // UK format
}

If you have many rows, convert before binding (SQL or DataTable) for better performance. Example pattern: add a DateTime column to the DataTable, loop the rows once to fill it with epoch.AddDays(clarionDays), then bind that column as a BoundField.

Troubleshooting notes:

  • Verify the exact Clarion epoch/offset by comparing a record with a known date (some systems apply an extra offset).
  • Handle nulls and invalid integers to avoid exceptions.
  • For international display, prefer formatting via CultureInfo or a TemplateField so you control localization.
  • For very large datasets, convert in the query (e.g., DATEADD in SQL) to reduce per-row server work.

If staying with VB, the same AddDays logic applies; move the conversion into binding rather than showing the raw number.

I have solved this problem as the clarion date is in number of days from 1/1/1900, i did a private function as follows:

Dim mydate As Date = "1/1/1900"
dim myDoodle as double = "76543"
        Dim MyAnswer As Date
        hfClarionNo.Value = "36161"

        lblMyDate.Text = (MyDodo - hfClarionNo.Value) - 2
        hfmyclarion.Value = MyDoodle

        MyAnswer = mydate.AddDays(lblMyDate.Text)
        Label2.Text = MyAnswer

put the above code in a loop and problem solved :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.