Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Julian date converter for google daterange search


  • Please log in to reply
19 replies to this topic
caveatrob
  • Members
  • 194 posts
  • Last active: Oct 10 2018 03:48 PM
  • Joined: 28 Oct 2006
Hi all,

Just found out (pretty late, probably) that Google has a daterange search qualifier that lets you search results over a particular range. Unfortunately, that range is in Julian format.

I'd like to assign hotkeys to go back one month, one year, and two years from the current date, respectively.

So,

I type "dr1m" and I should see:
daterange:<julian for one month ago>-<julian for today>

I type "dr1y" and I should see:
daterange:<julian for one year ago>-<julian for today>


I type "dr2y" and I should see:
daterange:<julian for two years ago>-<julian for today>

I don't need to parse out the hotkeys for "1 year" or "2 years" -- just need to get current julian date and the julian date for current - 1 month, 1 year, 2 years depending on which hotkey phrase I use.

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
until 2100, you can get the current julian date by subtracting 13 days from the current date.

caveatrob
  • Members
  • 194 posts
  • Last active: Oct 10 2018 03:48 PM
  • Joined: 28 Oct 2006
How do I do that? What format must the current date be in to subtract?

Am I missing something?

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
JulianDate := A_Now

JulianDate += -13, Days   ;NOT -=





FormatTime NiceJulianDate, %JulianDate%, MM/dd/yyyy

MsgBox, %JulianDate%`n%NiceJulianDate%



engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
::dr1m::
Send, % "daterange:" . JulianDate(-30) . "-" . JulianDate()
Return

::dr1y::
Send, % "daterange:" . JulianDate(-365) . "-" . JulianDate()
Return

::dr2y::
Send, % "daterange:" . JulianDate(-730) . "-" . JulianDate()
Return



JulianDate(lessDays=0, dateformat="MM/dd/yyyy"){
JulianDate := A_Now
JulianDate += -13, Days   ;NOT -=
JulianDate += lessDays, Days   ;NOT -=
FormatTime NiceJulianDate, %JulianDate%, %dateformat%
Return NiceJulianDate
}

/*
Note- I assume 30 days in a month

dr1m
daterange:06/07/2007-07/07/2007

dr1y
daterange:07/07/2006-07/07/2007

dr2y
daterange:07/07/2005-07/07/2007
*/ 
*Tested*

caveatrob
  • Members
  • 194 posts
  • Last active: Oct 10 2018 03:48 PM
  • Joined: 28 Oct 2006
I'm getting different results from converting for 1 month prior online:

daterange:2453937-2454302

garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005
here a link to explain different calenders
<!-- m -->http://www.ortelius....nder/jul_en.php<!-- m -->
and old gwbasic program
;-------------------------------- JULIAN CALENDER GWBASIC ----------------------------------------
9202 ' julian calender
9210 '2003-05-18 Days between two dates and Julian Calender for google xxx daterange:2452641-2452778
9211 'http://www.ortelius.de/kalender/jul_de.php      2003-05-18=2452778
9212 '
9213 CLS
9215 MX1=1:DX1=1:YX1=2003:JL1=2452641
9218 M2$=MID$(DATE$,1,2):MX2=VAL(M2$)
9220 D2$=MID$(DATE$,4,2):DX2=VAL(D2$)
9222 Y2$=MID$(DATE$,7,4):YX2=VAL(Y2$)
9224 DT$=Y2$+"-"+M2$+"-"+D2$
9226 YX=YX1:MX=MX1:DX=DX1:GOSUB 9240
9228 YX=YX2:MX=MX2:DX=DX2:NX=AX:GOSUB 9240
9230 NX=AX-NX:JL2=JL1+NX
9234 GOTO 9300
9240 'x
9241 ON MX GOTO 9250,9260,9250,9270,9250,9270,9250,9250,9270,9250,9270,9250
9242 'x unreal
9243 PRINT "Unreal Date!!!"
9244 RETURN
9250 'x 31
9251 IF DX>31 THEN 9242
9252 GOTO 9280
9260 'x 28
9261 IF YX/4<> INT(YX/4) THEN 9265
9263 IF YX/400 = INT(YX/400) THEN 9267
9264 IF YX/100<> INT(YX/100) THEN 9267
9265 'x
9266 IF DX>28 THEN 9242
9267 'x
9268 IF DX>29 THEN 9242
9269 GOTO 9280
9270 'x 30
9271 IF DX>30 THEN 9242
9280 'x
9281 DATA 0,31,59,90,120,151,181,212,243,273,304,334
9282 RESTORE 9281
9283 FOR HX=1 TO MX : READ AX : NEXT HX
9284 AX=AX+YX*365+INT(YX/4)+DX+1-INT(YX/100)+INT(YX/400)
9285 IF INT(YX/4)<>YX/4 THEN 9292
9286 IF YX/400=INT(YX/400) THEN 9288
9287 IF YX/100=INT(YX/100) THEN 9292
9288 'x
9289 IF MX>2 THEN 9292
9290 AX=AX-1
9292 'x
9293 RETURN
9300 'x
9310 JL3=JL2-3        ' minus 3 days
9311 JL3$=STR$(JL3):AL=LEN(JL3$):JL3$=RIGHT$(JL3$,AL-1):JL3=val(JL3$)
9312 JL2$=STR$(JL2):AL=LEN(JL2$):JL2$=RIGHT$(JL2$,AL-1):JL2=val(JL2$)
9313 'GOTO 9400
9314 LOCATE 2,1:COLOR 14,1
9315 PRINT "JULIAN CALENDER ";DT$;" =  ";JL2$
9316 PRINT "JULIAN  daterange:";JL3$;"-";JL2$
9317 PRINT "http://www.ortelius.de/kalender/jul_de.php"
9318 COLOR 0,7
9319 '
9320 'OPEN "JULIAN.TXT" FOR OUTPUT AS #1
9330 'PRINT #1," daterange:";JL3$;"-";JL2$
9340 'CLOSE #1
9341 PRINT
9345 PRINT "PUSH ANY KEY FOR QUIT"
9350 A$=INKEY$:IF A$="" THEN 9350 ELSE 9360
9360 'SYSTEM
9370 '
9400 'shell "notepad "+chr$(34)+"julian.txt"+chr$(34)
9420 XP$="daterange:"+JL3$+"-"+JL2$
9430 shell "c:\Progra~1\Mozill~1\firefox.exe "+chr$(34)+"http://www.google.com/search?hl=en&q="+XP$+chr$(34)
9450 system


engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
please point to some documentation from google about how to use this.

garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005
type in ( google )

daterange:2454301-2454302 autohotkey

found themas from last 2 days about autohotkey , example

Появилась обновленная версия небольшой утилиты AutoHotkey. Программа позволяет автоматизировать практически любую задачу для выполнения на компьютере, кроме того разрешает настраивать пользовательские горячие клавиши, а также назначать действия на джойстик и мышь. С ее помощью можно автоматизировать почти любые процессы путем нажатия всего нескольких комбинаций на клавиатуре, использовать автоматическую замену при печати, создавать формы ввода данных, интерфейсы и меню, форсировать переназначение стандартных кнопок на клавиатуре, джойстике или мыши.

В этом выпуске устранены проблемы с некоторыми опциями для управления, улучшена работа с горячими клавишами, а также внесены изменения в программный код (подробнее).

* AutoHotkey 1.0.47.02 (1.7 MB, open source).



engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
tested:
;msgbox, % JulianDate(A_now)
;msgbox, % JulianDate(TodayMinus(5))


::dr1m::
Send, % "daterange:" . JulianDate(TodayMinus(30)) . "-" . JulianDate(A_now)
Return

::dr1y::
Send, % "daterange:" . JulianDate(TodayMinus(365)) . "-" . JulianDate(A_now)
Return

::dr2y::
Send, % "daterange:" . JulianDate(TodayMinus(730)) . "-" . JulianDate(A_now)
Return



JulianDate(date){
;expects date in YYYYMMDDHH24MISS format (can be just YYYY, YYYYMM, or YYYYMMDD
;The Julian date is calculated by the number of days since January 1, 4713 BC. 
;For example, the Julian date for August 1, 2001 is 2452122.
;This fact is used when calculating the Julian Date
Julian20010801 = 2452122

date -= 20010801, Days
JulianDate := Julian20010801 + date
Return JulianDate
}

TodayMinus(days) {
result := A_Now
result += -days, days
Return result
}

/*
dr1m
daterange:2454271-2454301

dr1y
daterange:2453936-2454301

dr2y
daterange:2453571-2454301
*/ 


caveatrob
  • Members
  • 194 posts
  • Last active: Oct 10 2018 03:48 PM
  • Joined: 28 Oct 2006
Super cool! If you ever need a favor, let me know. I'm accomplished at origami, used to program, and sometimes write.

Rob

garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005
@engunneer
thank you for the function, autohotkey has good date calculation commands
more easier then gwbasic

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
engunneer's code is well suited for the purpose.
I am just posting my code here for my own backup.

MsgBox, % JulianDate( "20010801" ) ; Julian date for August 1, 2001 

JulianDate( YMD="", ChkYMD=1, Rn=1 ) {
  If ChkYMD
     FormatTime, YMD, %YMD%, yyyyMMdd

  Y := SubStr( YMD, 1,4 ) + 0
  M := SubStr( YMD, 5,2 ) + 0 
  D := SubStr( YMD, 7,2 ) + 0

  If ( M<=2 ) 
       M := M+12, Y := Y-1 
  A := 2 - Floor( Y/100 ) + Floor( Floor( Y/100 ) / 4 )
  B := Floor( 365.25  * ( Y+4716) )
  C := Floor( 30.6001 * ( M+1) )
Return Rn ? Floor( A+B+C+D -1524.5 ) : Round( A+B+C+D -1524.5, 1 )
}

:)

garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005
thank you Skan
I used now as follow
;if C1=JULIAN      ;example daterange:2454300-2454302 gwbasic [for google search 2007-07-21 minus 2 days ]
   {
       AL=gwbasic                          ;example search for
       DTS=%A_NOW%
       stringmid,Y4,DTS,1,4
       stringmid,M2,DTS,5,2
       stringmid,D2,DTS,7,2
       AS1:=(JulianDate(%Y4%%M2%%D2%))
       InputBox,AS2,Google Search Daterange,Start before x-days or (ENTER/OK for TODAY)
       if ErrorLevel <> 0
         return
       if AS2=
       AS2=0
       AS2:=ABS(AS2)     ;remove minus
       AS3:=(AS1-AS2)
       ;MsgBox,%JulianDate( "%Y4%%M2%%D2%" )
       run,http://www.google.com/search?hl=en&q=daterange:%AS3%-%AS1% %AL%

      JulianDate( YMD="", ChkYMD=1, Rn=1 )
          {
      If ChkYMD
          FormatTime, YMD, %YMD%, yyyyMMdd

        Y := SubStr( YMD, 1,4 ) + 0
        M := SubStr( YMD, 5,2 ) + 0
        D := SubStr( YMD, 7,2 ) + 0

        If ( M<=2 )
           M := M+12, Y := Y-1
        A := 2 - Floor( Y/100 ) + Floor( Floor( Y/100 ) / 4 )
        B := Floor( 365.25  * ( Y+4716) )
        C := Floor( 30.6001 * ( M+1) )
        Return Rn ? Floor( A+B+C+D -1524.5 ) : Round( A+B+C+D -1524.5, 1 )
        }
   return
   }


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear garry :) , I suggest you to use engunneer's version which is short, simple and effective for your particular requirement.
The only advantage my version has: It is not affected by AHK's date limitation of January, 1, 1601 , and any AD date should work.

Thanks. :)



A backup of my completed functions for anybody into Astronomy / Sidereal Astrology .

To convert a Gregorian DateTime Stamp to a Julian Date:

MsgBox, % JulianDate(A_NowUTC) 
MsgBox, % Floor(JulianDate(A_NowUTC)) ; Supress decimals

JulianDate( YYMMDDHHMISS="" )  { ; Accepts and Returns UTC

  FormatTime, YYMMDDHHMISS, %YYMMDDHHMISS%, yyyyMMddHHmmss 

  [color=red]YY[/color] := SubStr( YYMMDDHHMISS,  1,[color=red]4[/color] ) + 0
  MM := SubStr( YYMMDDHHMISS,  5,2 ) + 0 
  DD := SubStr( YYMMDDHHMISS,  7,2 ) + 0
  HH := SubStr( YYMMDDHHMISS,  9,2 ) + 0
  MI := SubStr( YYMMDDHHMISS, 11,2 ) + 0
  SS := SubStr( YYMMDDHHMISS, 13,2 ) + 0

  If ( MM<=2 ) 
       MM := MM+12, YY := YY-1 

  A := 2 - Floor( YY/100 ) + Floor( Floor( YY/100 ) / 4 )
  B := Floor( 365.25  * ( YY+4716) )
  C := Floor( 30.6001 * ( MM+1) )
  T := ( HH + ( MI/60.0 ) + ( SS/3600.0 ) ) / 24.000000 

Return A+B+C+DD-1524.5+T
}

To convert back a Julian date to a Gregorian DateTime Stamp:

Gregorian( Julian ) {

 g1601 := "16010101000000" , j1601 := 2305813.5
 Julian += 0.0
 StringSplit, U, Julian, .
 dsj := U1-j1601  ,  U2 := ("." U2) 
 U2 += 0.000000
 Sec := Round((86400*(U2*100))/100 )
 g1601 += %dsj%, Days
 g1601 += %Sec%, Seconds

Return g1601
}

Links:
[*:2hlloj8e]Wikipedia Julian Day
[*:2hlloj8e]Online Julian<>Gregorian conversion calculator