473,372 Members | 1,113 Online

# convert gregorian date to jalay date

how i can convert gregorian date to jalaly(Iran date)
with vb.net
Nov 17 '05 #1
1 2182
"h_ghanaty" <h_*******@yahoo.com> wrote in message
news:0a****************************@phx.gbl...
how i can convert gregorian date to jalaly(Iran date)
with vb.net

I don't know VB.NET but I came up with this C# code which you can probably
translate pretty easily. It uses the 8-of-33 leap year method which only
works within a certain range of years because of how the Jalali leap years
are calculated.

const long ticksPerDay = 864000000000L;

static int[] leapFlag =
{0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0 ,0,1,0,0,0,1,0,0};

public static void GetJalaliDate(DateTime time, out int year, out int month,
out int day)
{
const int daysIn33Years = 365 * 33 + 8;
int d = (int) (time.Ticks / ticksPerDay) - 226529;
year = (d / daysIn33Years) * 33;
d %= daysIn33Years;
for (int i=0; i<33; i++)
{
int daysInYear = 365 + leapFlag[i];
if (d < daysInYear)
break;
d -= daysInYear;
year++;
}
if (d < 186)
{
month = 1 + d / 31;
day = 1 + d % 31;
}
else
{
d -= 186;
month = 7 + d / 30;
day = 1 + d % 30;
}
}

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

### Similar topics

 4 by: Richard Hollenbeck | last post by: I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and... 5 by: goochey | last post by: I'm trying to convert a Julian Date (Format "4365") into an actual calendar date in Visual Basic, can anyone help me out with this. 5 by: SalimShahzad | last post by: Dear Respected Gurus, I need a coding assistant converting from gregorian to hijri and vice versa. I have problem with this codes. the problem Gregorian to Hijri gives 100% results. when i enter... 1 by: Raja | last post by: Hi Anyone has any idea of how to convert Julian Date (eg. 12744057862..) to a VB.NET date time. Thanks in advance. 1 by: Sam | last post by: How do I convert Julian Date to Calendar Date in ASP.Net 1.1 based on following guideline found at Internet? To convert Julian date to Gregorian date: double JD = 2299160.5; double Z =... 15 by: JenHu | last post by: Hi expert, I have a data field (birthdate) contains a datetime datatype (mm/dd/yyyy), how can I convert to mmdd?? say, the birthday is 8/1/1979 and convert to mmdd DOB =... 4 by: Holmsey | last post by: Hi I have to convert am today's date and time (now) to a webservice. The example the web service gives was "1163313527144#" which comes out to 12/31/1969 06:00 PM. How do I convert a date to a 13... 3 by: Lonifasiko | last post by: Hi, I want to convert an UTC time to a Date object in Javascript. The UTC time we have is a string that looks like "1160720058.377452373" for example. I've done it in Java but I'm not able... 3 by: nisse2562 | last post by: this code: http://pastebin.com/f168570c8 gives the compile error: test_templates.cpp: In function 'int main(int, char**)': test_templates.cpp:51: error: expected `(' before 'g'... 1 by: CloudSolutions | last post by: Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now... 0 by: isladogs | last post by: The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former... 0 by: taylorcarr | last post by: A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,... 0 by: aa123db | last post by: Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function \$name\$ (\$parameters\$) { } ... 0 by: ryjfgjl | last post by: If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming... 0 by: emmanuelkatto | last post by: Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel 0 by: BarryA | last post by: What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress... 1 by: nemocccc | last post by: hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions? 0 by: Hystou | last post by: There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...