Sunrise/Sunset script

I was looking for some data the other day (unrelated to this), and on someone’s website, at the bottom of their left menu, they had a nice little Sunrise and Sunset data box that also had a colored pie chart of sunlight and darkness hours.

Should have bookmarked it because now I cannot find it. Ring a bell with anyone? Is the script for this available?

Could it be this one (mid page)?

No. The pie was similar, but a lot smaller and it, plus the Sunrise and Sunset times were together in a little box near the bottom of the websites left side menu.

Something like this, perhaps?

No. Not all all. I don’t even see a pie chart on there.

I’ve found it. Thanks.

Where is it?

I’m not sure yet if the person wants to share it or not.
If they do, I’ll post then.

It turns out it was the one I have on my site. Someone else came up with the graph and posted it on one of the forums several years ago and used that along with some WD tags on the bottom of my menu.

    <div style="font-size: 8pt; text-align: center;">
            //Make piechart
            $testtime = substr($hoursofpossibledaylight,0,2);
            $testminute = substr($hoursofpossibledaylight,3,2);
            <img src="
            &amp;chd=t:<?php echo $testljus;?>,<?php echo $testmorker;?>
            " alt="graph"/>

            <span style="position: relative; top: -107px;">
            $time_arr = explode(':', $hoursofpossibledaylight, 2);
            echo (int)$time_arr[0] . " hrs " . (int)$time_arr[1] . " min";
            echo '
of Daylight Today
            <span style="position: relative; top: -94px; left: 0px; font-size: 1.0em;">        <!-- was -5 -->
                <?php echo $testljus . "%"; ?>
            <span style="position: relative; top: -94px; left: 0px; font-size: 1.0em; color:#FFFFFF;">      <!-- was 5 -->
                <?php echo $testmorker . "%"; ?>
            <span style="position: relative; top: -78px;">
            echo '
Which is 
            $time_arr = explode(':', $changeinday);
            if (substr($time_arr[0],0,1) != "-") {         // -0 when getting shorter
                echo (int)$time_arr[1] . " min Longer";
            } else {
                echo (int)$time_arr[1] . " min Shorter";
            echo ('
Than Yesterday');

  • Jim


Thanks Jim. I’ve been busy today so hadn’t even had a chance to work on it yet or email you back about posting it here.
Didn’t figure you would mind but always want to make sure first.

Looking at the new and the old google pie chart api’s after getting just a placeholder for an image, is there some javascript code needed as well?

You just need the html, this

<img src="

Will produce this:

I should have mentioned that you need the appropriate tags in testtags (or similar) to energize the needed variables.

  • Jim

Thanks again Jim.
Got it showing on my Live pages.

Thanks, Jim. The variables were in my testtags.php file. Somehow the string for the image got mangled because of the white space and new lines. I eliminated the extra characters, and suddenly the string worked. It’s live now toward the bottom of my menubar.


It looks like you’ll need to tweak the css in the code … I had to do some funky stuff to get everything to display the way I wanted. It looks like Rick’s worked out ok.

  • Jim

Yes, I had to move some things a bit and changed a few colors to match my site.

Hi Jerry,

I am still not getting the graph, I just get the placeholder “graph”. I can’t seem to get the code to work. Could you post your code.




I have it on my site now with code tweaks to fit my site colours/ layout, including rotating the chart to show daylight hours starting at the top (zero degrees) and adding the actual hours to the chart as well as percentages. I didn’t get the chart to show until I put the Google API chart code all on one line without spaces.

Hi Martyn,

Thanks for the info. I got it working after several attempts, I just need to adjust things now.

Thanks again,