Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Getting DateTime in Win32

marshallc
Beginner
1,966 Views
Hi,
Is there a way to retrieve the system's date and time in a Win32 fashion or is it just a matter of making a call to date_and_time or getdat?
Thanks,
Chad
0 Kudos
13 Replies
Paul_Curtis
Valued Contributor I
1,966 Views
Code:
	TYPE(T_SYSTEMTIME)	:: st

	! note -- all SYSTEMTIME components are INTEGER*2
	!TYPE T_SYSTEMTIME
	!SEQUENCE
	!  integer(WORD) wYear		 ! knowns  WORD 
	!  integer(WORD) wMonth		 ! knowns  WORD 
	!  integer(WORD) wDayOfWeek		 ! knowns  WORD 
	!  integer(WORD) wDay			 ! knowns  WORD 
	!  integer(WORD) wHour		 ! knowns  WORD 
	!  integer(WORD) wMinute		 ! knowns  WORD 
	!  integer(WORD) wSecond		 ! knowns  WORD 
	!  integer(WORD) wMilliseconds	 ! knowns  WORD 
	!END TYPE

	CALL GetLocalTime (st)


0 Kudos
marshallc
Beginner
1,966 Views

Paul-Curtis,

How did you learn about this function/type/call? I have a Programming Windows book which I hoped would have some info on Win32 APIs, but it doesn't seem to contain the info I need.

Chad

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,966 Views
Well, Petzold is a tutorial book rather than reference.

The primary referential material is Microsoft "Platform SDK" documentation.
- it is bundled with CVF online help
- however (probably due to licensing issues) it is not bundled with IVF documentation. You can find it in MSDN if you installed it with VS.NET
- it is available online on MSDN site
- You can freely download an older, but quite useful and concise version from Borland

HTH
Jugoslav
0 Kudos
marshallc
Beginner
1,966 Views

Thanks Jugoslav! If I wanted to retrieve the information from this, I would do the following...

Year_Now = st.wYear

Right?

Man, Win32 library is HUGE! I know for those that have been working with it for a long time that's kind of like a "duh" statement, but from a newbie standpoint, it's like being given a haystack and trying to find the needle. The good thing is that there is a way to search it online and offline.

Chad

0 Kudos
Paul_Curtis
Valued Contributor I
1,966 Views

Components within defined types are punctuated by % or period.

If your variable is a standard F90 integer, then

Year_Now = INT4(st%wYear)

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,966 Views
Right. (Except, you can save yourself a latter hassle by using standard form st%wYear).

Windows API is huge indeed. If you can find a "book-chapter" version of documentation (such as MSDN or CVF version), you will find that docs are fairly well organized (Introduction, detailed explanations and reference chapter) and routines are mostly logically named (except when not :-) ). However, that doesn't make it much easier to grab (nor every programmer needs all of it -- my personal rough estimate is that I didn't use more than 30% of it). Petzold is IMO an excellent starting book, but it mostly discuses typical GUI aspects. Jerry Richter's "Advanced Windows" is more comprehensive but also more advanced.

Jugoslav
0 Kudos
marshallc
Beginner
1,966 Views
Awesome! Thanks guys!
0 Kudos
marshallc
Beginner
1,966 Views
I'm looking in MSDN, but I haven't found whether there is a function for calculating the Julian date. There are a few calls that I don't think I can apply to the Fortran code. I'm not sure what the limitations are in using functions in other languages.
I searched the forum and found code that calculates the Julian date, but I didn't see any reference to a Win32 API call that would retrieve this information.
Does anyone know if this exists?
0 Kudos
Steven_L_Intel1
Employee
1,966 Views
Not that I know of, but there are zillions of Julian Date routines out there (in Fortran) that will take the values you get from DATE_AND_TIME and create a Julian date for you. This is a classic beginning programming assignment.
0 Kudos
Paul_Curtis
Valued Contributor I
1,966 Views
Code:
	FUNCTION julian_date (yyyy, mm, dd) RESULT (julian)
		IMPLICIT NONE
		!          converts calendar date to Julian date
		!          cf Fliegel & Van Flandern, CACM 11(10):657, 1968
		!          example: julian_date(1970,1,1)=2440588
		INTEGER,INTENT(IN)           :: yyyy,mm,dd
		INTEGER                      :: julian
		julian = dd - 32075 + 1461*(yyyy + 4800 + (mm - 14)/12)/4 +  &
				 367*(mm - 2 - ((mm - 14)/12)*12)/12 -               &
				 3*((yyyy + 4900 + (mm - 14)/12)/100)/4
	END FUNCTION julian_date
  

	SUBROUTINE get_ymd (jd, yyyy, mm, dd)
		IMPLICIT NONE
		!          expands a Julian date into a calendar date
		!          cf Fliegel & Van Flandern, CACM 11(10):657, 1968
		INTEGER,INTENT(IN)           :: jd
		INTEGER,INTENT(OUT)          :: yyyy,mm,dd
		INTEGER                      :: l,n
		l		= jd + 68569
		n		= 4*l/146097
		l		= l - (146097*n + 3)/4
		yyyy	= 4000*(l + 1)/1461001
		l		= l - 1461*yyyy/4 + 31
		mm		= 80*l/2447
		dd		= l - 2447*mm/80
		l		= mm/11
		mm		= mm + 2 - 12*l
		yyyy	= 100*(n - 49) + yyyy + l
	END SUBROUTINE get_ymd

  
	INTEGER FUNCTION dow (yyyy,mm,dd)
		IMPLICIT NONE
		!          Day_Of_Week: (0=Sunday,1=Monday...6=Saturday)
		!          cf J.D.Robertson, CACM 15(10):918
		INTEGER,INTENT(IN)           :: yyyy,mm,dd
		dow = MOD((13*(mm+10-(mm+10)/13*12)-1)/5+dd+77           &
			  +5*(yyyy+(mm-14)/12-(yyyy+(mm-14)/12)/100*100)/4   &
			  +(yyyy+(mm-14)/12)/400-(yyyy+(mm-14)/12)/100*2,7)
	END FUNCTION dow

              
	INTEGER FUNCTION ndiy (yyyy,mm,dd)
		IMPLICIT NONE
		!          day count in year
		!          cf J.D.Robertson, CACM 15(10):918
		INTEGER,INTENT(IN)           :: yyyy,mm,dd
		ndiy = 3055*(mm+2)/100-(mm+10)/13*2-91               &
			   +(1-(MOD(yyyy,4)+3)/4+(MOD(yyyy,100)+99)/100  &
			   -(MOD(yyyy,400)+399)/400)*(mm+10)/13+dd 
	END FUNCTION ndiy


0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,966 Views
Actually, SystemTimeToFileTime and FileTimeToSystemTime are Win32 routines for conversion between Julian date (FILETIME = INTEGER(8)) and SYSTEMTIME structure.

Jugoslav
0 Kudos
marshallc
Beginner
1,966 Views

Yeah, I remember having to do this for a programming assignment about 10 years ago... or has it been longer... time flies :) Of course, I haven't been developing that long. I've worn so many hats since then. WithWin32 programming, I kept hearingthat there wereAPIs for everything you wanted to do. Unless Microsoft didn't want to take away from the professor's programming lessons, I was thinking there has to be an API for calculating the Julian date. I was looking around, but I didn't see anything that matched.

Paul-Curtis, thanks for the code samples. This helps me in not having to reinvent the wheel ;) Jugoslav, I saw the APIs that you mentioned, but I didn't think they would apply. I'll take another look at them. Thanks for pointing them out :)

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,966 Views
Yes, I didn't know that the term "Julian date" has well-defined starting point (checking... Jan 1 4713 BC) -- I thought the term refers to any system of time counting from an arbitrary initial date. FILETIME certainly fulfills the latter definition, but it's not a "Julian date". Indeed, Win32 API doesn't have one.

Jugoslav
0 Kudos
Reply