# strtotime equivelant -

Page 1 of 1

## 1 Replies - 29443 Views - Last Post: 20 June 2011 - 12:16 PM

### #1 gregwhitworth

• Tired.

Reputation: 221
• Posts: 1,613
• Joined: 20-January 09

# strtotime equivelant -

Posted 20 June 2011 - 10:43 AM

Ok - I have the following PHP I need to convert to AS3 and I am having a rough time (no pun intened) with time:

```\$days = (strtotime(date("Y-m-d H:i:s")) - strtotime(\$date)) / (60 * 60 * 24);
\$subtract = \$days * 105;
\$newAmount = 621350 - \$subtract;

```

Ok. So here am I trying to do the exact same thing with AS3:

```function countDays( startDate:Date, endDate:Date ):int
{
var oneDay:int = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var diffDays:int = Math.round(Math.abs((startDate.getTime() - endDate.getTime())/(oneDay)));
return diffDays;
}

var today = new Date();
var startYear = 2011;
var startVal = 621350;

var currentYear = today.getFullYear();
var curHours = today.getHours();
var hourDiff = 24 - curHours;
var yearDiff = currentYear - startYear;
var subtract = yearDiff * 38400;
var newStartVal = startVal - subtract;
var days = countDays(today, new Date(2021, 12, 31));
var hoursInDays = days * 24;
var totalHours = hoursInDays - hourDiff;
var hoursIntoDays = totalHours/24;

newStartVal = newStartVal - (hoursIntoDays * 105);
```

So the PHP one will keep the counter up date by the second and that's what I'm trying to get to with the Actionscript one.

--

Greg

Is This A Good Question/Topic? 0

## Replies To: strtotime equivelant -

### #2 gregwhitworth

• Tired.

Reputation: 221
• Posts: 1,613
• Joined: 20-January 09

## Re: strtotime equivelant -

Posted 20 June 2011 - 12:16 PM

Ok. So I found the following method, .time. It returns a date object in milleseconds which I then was able to convert to seconds. Here's the new math:

```var i:Array = new Array();
i['today'] = new Date();
i['xmldate'] = i['today'].fullYear + "/01/01 00:00";
i['tdyInSec'] = i['today'].getTime()/1000; // Milleseconds / 1000 to get seconds
var tdyInSecNum:Number = Math.round(Math.abs(i['tdyInSec']));

i['strtYr'] = new Date(2011, 05, 01);
i['strtYrInSec'] = i['strtYr'].getTime()/1000; // Milleseconds / 1000 to get seconds
var strtYrInSecNum:Number = Math.round(Math.abs(i['strtYrInSec']));

i['diffSec'] = tdyInSecNum - strtYrInSecNum;
i['barrels2Subtract'] = Math.round(Math.abs(i['diffSec'] * .0012));
i['totalBarrels'] = 621000 - i['barrels2Subtract'];

for(var key:String in i) {
trace(key + ": " + i[key]);
}
trace('strtYrInSecNum: ' + strtYrInSecNum);
trace('tdyInSecNum: ' + tdyInSecNum);

```

Works like a charm.