Solved

Converting $limit_time = time() - 300

Posted on 2004-04-23
6
186 Views
Last Modified: 2010-04-05
We are running e web site, which has an online user counter. This is the php code placed on the site.
      
                $limit_time = time() - 300; // 5 Minute time out. 60 * 5 = 300      
      $sqla = mysql_query("SELECT * FROM ppl_online WHERE UNIX_TIMESTAMP(activity) >= $limit_time GROUP BY ip_address") or die (mysql_error());
      if ($sqla == TRUE)
      {
            $visits = mysql_num_rows($sqla);
      }
      else
      {
            $visits = 0;
      }

can someone convert $limit_time to a variable which delphi can understand..
0
Comment
Question by:bilgehanyildirim
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10904189

   hey man .... this is the Delphi section and your code is PHP....

   Anyway .... you can format the date to string .... use date() function

   string date ( string format [, int timestamp])

   Let's say
   
        $delphi_var = date("m.d.y H:i:s", $limit_time);  // you date will be string in format 24.04.2004 00:56:36

   From Delphi you can use StrToDateTime function ....
0
 

Author Comment

by:bilgehanyildirim
ID: 10904214
Sorry but this is a question regarding delphi. May be I couldn't understand.

On my site I can run thus sql
$sqla = mysql_query("SELECT * FROM ppl_online WHERE UNIX_TIMESTAMP(activity) >= $limit_time GROUP BY ip_address") or die (mysql_error());

But in my delphi project I could't convert $limit_time = time() - 300 to a string so that I could use it like

sql := 'SELECT * FROM ppl_online WHERE UNIX_TIMESTAMP(activity) >='+Converted_Time+'GROUP BY ip_address';

I think this is a DELPHI question ;)
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10904294

   use the MySQL function DATE_FORMAT

  Example :

  SELECT DATE_FORMAT('2003-10-03', GET_FORMAT(DATE, 'EUR')

  This is string...
  I am not quite sure if there was function DATETIME_FORMAT. Please check the Documentation, because I don't have it now....
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:bilgehanyildirim
ID: 10913689
didn't work mate.
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10915771

   which part exactly don't work ?
0
 
LVL 17

Accepted Solution

by:
geobul earned 250 total points
ID: 10929799
Hi,

Try this:

function UnixTimeToDateTime(const UnixTime: Integer): TDateTime;
var
  FileTime: TFileTime;
  SystemTime: TSystemTime;
  I: Int64;
begin
  // first convert unix time to a Win32 file time
  I := Int64(UnixTime) * Int64(10000000) + 116444736000000000;
  FileTime.dwLowDateTime := DWORD(I);
  FileTime.dwHighDateTime := I shr 32;

  // now convert to system time
  FileTimeToSystemTime(FileTime, SystemTime);

  // and finally convert the system time to TDateTime
  Result := SystemTimeToDateTime(SystemTime);
end;

Regards, Geo
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Comparing dates in Delphi. Greater than/ Less than 3 150
When i run adoquery my application freezes 26 165
Firemonkey android show image from resource ? 1 42
CheckListBox usage 3 58
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question