• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1858
  • Last Modified:

convert julian date in c#

I've got to convert a julian date to a normal date in c# and it is kicking - not in a friendly way. any sugestions?
Label lblDocDate = (Label)e.Row.FindControl("lblDocDate");
double timestamp = Convert.ToDouble(2455308);//this is 04/21/10 //Convert.ToDouble(drv["reserved_isvn2"]);
System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
dateTime = dateTime.AddMilliseconds(timestamp);
string printDate = dateTime.ToShortDateString();
lblDocDate.Text = printDate.ToString(); // returns: 1/29/1970 10:01 AM

Open in new window

0
vicomin
Asked:
vicomin
  • 4
  • 3
  • 2
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
vicominAuthor Commented:
it errors on line:

if ((month == 1)(month == 2))

Error: Method name expected
0
 
rajapandian_81Commented:
Refer below function in below link:

http://forums.asp.net/p/1173999/1972455.aspx
public static DateTime ConvertFromJulian(int m_JulianDate)
        {

            long L = m_JulianDate + 68569;
            long N = (long) ((4*L)/146097) ;
            L = L - ((long)((146097 * N + 3)/4) );
            long I = (long) ((4000 *(L + 1)/1461001)) ;
            L = L - (long)((1461*I)/4) + 31; 
            long J = (long)((80*L)/2447); 
            int Day = (int)(L - (long)((2447*J)/80));
            L=(long)(J/11) ;
            int Month = (int)(J + 2 - 12*L);
            int Year = (int)(100*(N-49) + I + L) ;

            DateTime dt = new DateTime(Year,Month,Day);
            return dt;
        }

Open in new window

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
vicominAuthor Commented:
another one in the last return:

return date;
    }

Error: Use of unassigned local variable 'date'
0
 
Éric MoreauSenior .Net ConsultantCommented:
you need to put a OR condition between the 2 parts of the conditions
0
 
vicominAuthor Commented:
emoreau - did this:
if ((month == 1) ||(month == 2))

rajapandian_81 - any idea how to just get the date and not time?
0
 
rajapandian_81Commented:
To get only date from datetime variable use below code:

string strDate = dt.ToString("MM/dd/yy");

Open in new window

0
 
vicominAuthor Commented:
       DateTime dt = new DateTime(Year, Month, Day);
        string strDate = dt.ToString("MM/dd/yy");
        //return dt;
        return strDate.ToString();

gives me: Cannot implicitly convert type 'string' to 'System.DateTime'
0
 
rajapandian_81Commented:
Change return type from DateTime to string like below


change the line
public static DateTime ConvertFromJulian(int m_JulianDate)

to
public static string ConvertFromJulian(int m_JulianDate)
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now