iLite’s Weblog

January 5, 2011

Determining the number of days between to UNIX timestamps

Filed under: PHP — ilite @ 11:37 am

So I needed to know how many days there were between to UNIX timestamp values, and here is the code for those who may also need it.

function dateDiffUnix($startDate) {

echo ‘$start_date ‘.$startDate.’ – ‘.date(‘Y m d G:i:s’, $startDate).’<br />’;
$endDate = time();
echo ‘$end_date ‘.$endDate.’ – ‘.date(‘Y m d G:i:s’, $endDate).’<br />’;
$difference = $endDate – $startDate;
return round($difference / 86400);
}
echo ‘Unix date difference: ‘.dateDiffUnix(“1292479971″);        // start time
In my case the start date will be passed in as a value from the database, but for this sample, a hard-coded value will suffice.

 

 

 

January 4, 2011

Making a List item scroll

Filed under: AMFPHP,Flex — ilite @ 7:25 am

Have you ever wanted your List items to automatically scroll…. well I have. I am building a Flex application that shows the latest 10 items in a list container.

I would like to cycle through the list once every 5 seconds, taking the last item and displaying it at the top. I am using AMFPHP to retrieve the content from a MySQL database.

 

So this is what I did

private function load():void
{
gateway = new RemotingConnection(serverName);
gateway.call(“mydetails”, new Responder(onResult, onFault));
}
private function onResult(result:Array):void
{
ac = new ArrayCollection()
for each(item in result){
var o:TicketVO = new TicketVO();
o.ticketId = item["ticketid"];
o.summary = item["summary"];
ac.addItem(o);
}
lRenderer.dataProvider = ac;                                                              // lRenderer is the name of my List container
timer = new Timer(5000, 0);
timer.addEventListener(TimerEvent.TIMER, updateList, false, 0, true);
timer.start();
}
private function updateList(event:TimerEvent):void
{
var len:Number = ac.length;
var i:Object = new Object();
i = lRenderer.dataProvider.getItemAt(len-1, 1);                   // Get the last item in the list
lRenderer.dataProvider.removeItemAt(len-1);                    // Remove the item from the list
lRenderer.dataProvider.addItemAt(i,0);                                 // Add it to the top of the list
}

The above is just a snapshot of the code I used.

 

Hope that helps some.

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.