Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff
Author Message
XenoMorpH
Hangin' Around


Joined: Jan 23, 2004
Posts: 37
Location: Netherlands

PostPosted: Fri Aug 25, 2006 3:44 pm Reply with quote

I'm looking for a script which converts a dat+time to a timestamp:
Like:
Friday August 25th 2006 22:44:01 (GMT) converted to 1156545841

I can only find online coverters, but no scripts which can be implanted in my own scripts. Does anyone know how to do this?
 
View user's profile Send private message Visit poster's website
Guardian2003
Site Admin


Joined: Aug 28, 2003
Posts: 6792
Location: Ha Noi, Viet Nam

PostPosted: Sat Aug 26, 2006 1:53 am Reply with quote

Code:


<?php
  $unixtime = time();
  echo "unixtime: " . $unixtime . "<br />";
  echo "formatted: " . date("F j, Y, g:i a",$unixtime) . "<p />";
  $settime = "1104537600";
  echo "settime: " . $settime . "<br />";
  echo "formatted: " . date("F j, Y, g:i a",$settime) . "<p />";
?>

Everything you need is there Wink
 
View user's profile Send private message Send e-mail
XenoMorpH
PostPosted: Sat Aug 26, 2006 2:06 am Reply with quote

Tnx, I'll take a look at it Smile
 
Guardian2003
PostPosted: Sat Aug 26, 2006 2:09 am Reply with quote

Let me know if it helps Smile
 
XenoMorpH
PostPosted: Sat Aug 26, 2006 2:16 am Reply with quote

Doesn't this script only convert a timesttamp to date+time and not visaversa
 
Guardian2003
PostPosted: Sat Aug 26, 2006 2:22 am Reply with quote

Yes your right.
Have you looked at this Only registered users can see links on this board! Get registered or login!
 
XenoMorpH
PostPosted: Sat Aug 26, 2006 2:27 am Reply with quote

Not yet....I'll take a look at it Smile. Tnx
 
Guardian2003
PostPosted: Sat Aug 26, 2006 2:29 am Reply with quote

If you are storing formatted dates in a DB you can retrieve the timestamp by using a query where in the column list of the mysql query, put UNIX_TIMESTAMP(column name) - just thought I would mention it as you might be working with sql data.
 
XenoMorpH
PostPosted: Sat Aug 26, 2006 2:33 am Reply with quote

Yeah, I'm putting Friday August 25th 2006 22:44:01 (GMT) into a database as a timestamp, didn't know it could be done by using UNIX_TIMESTAMP. How'd u suguest to insert it, I haven't used this before...
 
Guardian2003
PostPosted: Sat Aug 26, 2006 2:56 am Reply with quote

There are a number of ways you can do this depending on your needs so I would recommend a google search for UNIX_TIMESTAMP to ensure it will do what you need.

I have not tested it but something like
Code:


SELECT * FROM table WHERE UNIX_TIMESTAMP(date_field)
should give you whatever the date/time is stored there but in unixtime format rather than whatever formatting it is in in the table.

Here's another interesting read Only registered users can see links on this board! Get registered or login!
 
XenoMorpH
PostPosted: Sat Aug 26, 2006 2:58 am Reply with quote

Tnx for the information Smile I hope I have enough information to make the script I'm looking for Smile
 
Guardian2003
PostPosted: Sat Aug 26, 2006 3:06 am Reply with quote

Not a problem, I spent an entire day reading reading up on PHP's ip2long and long2ip functions yesterday just to do one simple thing.
 
XenoMorpH
PostPosted: Sat Aug 26, 2006 6:35 am Reply with quote

I created a little script (it might look ugly, but it works Smile) to convert
Friday 25th of August 2006 10:41:33 PM GMT to a timestamp

Code:
<?php 


date_default_timezone_set('GMT');
$p="Friday 25th of August 2006 10:41:33 PM GMT";
$fsd = explode(" ", $p);

echo "".substr($p, 0)."";

echo"<br>";
global $s, $s1;

$monthn = array(
   "January" => "01",
   "February" => "02",
   "March" => "03",
   "April" => "04",
   "May" => "05",
   "June" => "06",
   "July" => "07",
   "August" => "08",
   "September" => "09",
   "October" => "10",
   "November" => "11",
   "December" => "12"
);


$fs = explode(":", $fsd[5]);
   $day=substr($fsd[1], 0, 2);
    $month=$monthn[$fsd[3]];
    $year=$fsd[4];
   if($fsd[6]=="PM"){$hour=$fs[0]+12;}
   else{
   $hour=$fs[0];
   }
   $min=$fs[1];
   $sec=$fs[2];
//convert it to unix timestamp
   

     $date=mktime($hour,$min,$sec,$month,$day,$year);


//caluculate our time from GMT time
   echo"$date";
   echo"<br>";
   print(date("m-d-Y h:i:s A T", $date));
?>


Maybe some1 else may find this usefull Very Happy
 
Guardian2003
PostPosted: Sat Aug 26, 2006 7:35 am Reply with quote

Excellent thanks for sharing Smile
 
evaders99
Former Moderator in Good Standing


Joined: Apr 30, 2004
Posts: 3221

PostPosted: Mon Aug 28, 2006 11:18 am Reply with quote

Does this not work for you? Only registered users can see links on this board! Get registered or login!

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©