Adding my monthly usage billing to my website's dashboard
I have a dashboard for a website I run, and I wanted to add my monthly usage bill that it’s currently set at. (For example, for 10 hours @ $0.03/hr, it should show $0.30 on my dashboard.)
The thing is, it’s slightly inaccurate, missing 6 cents. (Essentially, 2 hours is missing.)
I am using PHP and Carbon to do this:
$startOfMonth = new Carbon('first day of this month midnight', 'America/New_York'); $currentDay = new Carbon('now', 'America/New_York'); return $currentDay->diffInHours($startOfMonth);
As of right now, it should be 640+ hours for the duration of this month. I set the timezone as New York (I’m in the UK) as I assumed the billing process is handled at DO’s headquarters which is in NYC.
I am also using Graham Campbell’s Laravel-DigitalOcean repo and it does output an object which tells me the hourly cost.
This is how I’m doing the mathematics:
$droplet->getPriceHourly() * $droplet->getHourDurationThisMonth()
What am I doing wrong to receive this inaccurate output?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.×