PHP - Time Only Conversion
I need to compare current time to data based time.
Time in the database is in this format > 00:00:00 Easy enough. >>>>What I need is to convert "00:00:00" format into "time();" format<<<< The opposite is below...it's all I could come up with so far. <? $gettime = time(); $displayTime = date('H:i:s', time()); echo $displayTime; ?> Thank you. Similar TutorialsHi - I have been searching for a way to select the stored time from a database (stored in 24h format - 13:20:00) and display it as 12h format. I have checked a number of forums and nothing quite seems to fit the bill. I would like it to display as 2:00pm, 12:00am, etc. Here is what I have so far: $sql = ('SELECT * FROM events WHERE active="1" AND event_date >= CURRENT_DATE AND MONTH(event_date) = 1 order by event_date ASC, event_start ASC'); $result = mysql_query($sql); $num_rows = mysql_num_rows($result); // Yes Item if (!($num_rows == 0)) { $myrow = mysql_fetch_array($result); echo ('<span class="bold" style="font-size:14px">January</span>'); do { printf ('<span>Event Time: %s', $myrow['event_start']); if ($myrow['event_end'] != '') { printf (' to %s', $myrow['event_end']); } } while ($myrow = mysql_fetch_array($result)); } Right now this just shows the regular 24h format (hh:mm:ss) for any events in the month of January. I would like both "event_start" and "event_end" to show up in 12h format. I have tried a number of things but none of it works. I'm SURE it is something simple that I have missed. Thanks in advance for any help. I am writing an app that takes ofx banking files files on convert them to csv for excel or importation into sql. I am on the last task. Converting the nonstandard date:time stamp. I am using preg_replace(). I am not the best at regular expressions. I am getting this error: "Warning: preg_replace() [function.preg-replace]: Unknown modifier '\' in C:\xampp\htdocs\banking\ofx-date.php on line 13" CODE: // Date Time 20110228000600 (2011/02/28/, 00:06:00) // Expected Return '<DTPOSTED>2011/02/28,00:06:00' $ofxDate = '<DTPOSTED>20110228000600'; $ofxNewDate = substr($ofxDate,0,10) . substr($ofxDate,10,4) . '/' . substr($ofxDate,14,2) . '/' . substr($ofxDate,16,2) . ',' . substr($ofxDate,18,2) . ':' . substr($ofxDate,20,2) . ':' . substr($ofxDate,22,2); echo htmlentities($ofxNewDate) . PHP_EOL;; $patternA = '/<DTPOSTED>/\b[0-9]+\b'; //$replacement = '/<DTPOSTED>/'; $stringB = preg_replace($patternA, $ofxNewDate, ofxDate); echo htmlentities($StringB) . PHP_EOL; Purpose: To get time zone of a remote file in my time zone. I have to download a file daily (mp3, don't worry its legal!) from BBC. Problem is that sometimes BBC doesn't update the file and i have to download entire file to check if it has been updated or not. Hence i decided to code a page that gives me date and time of that remote file. I have successfully compiled the code (that i got from internet). But the time returns in EST. I want the time in IST (indian std time Asia/Calcutta). CURLINFO_FILETIME has bee used. Below is code. Pls suggest me how to convert EST to IST - Warning: I am a newbie. But i can follow instructions Code: [Select] <?php $curl = curl_init('http://wsdownload.bbc.co.uk/hindi/tx/32mp3/din_bhar.mp3'); //don't fetch the actual page, you only want headers curl_setopt($curl, CURLOPT_NOBODY, true); //stop it from outputting stuff to stdout curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // attempt to retrieve the modification date curl_setopt($curl, CURLOPT_FILETIME, true); $result = curl_exec($curl); if ($result === false) { die (curl_error($curl)); } $timestamp = curl_getinfo($curl, CURLINFO_FILETIME); if ($timestamp != -1) { //otherwise unknown echo "BBC Hindi was last modified" . date("d-m-Y h:i:s A T", $timestamp); //etc } ?> I have used it with custom getRemoteFileSize function he - Code: [Select] http://island.web44.net/bbc.php Hi, for my purposes, I can only use core PHP function (no PEAR for eg) to convert SQL to XML, should I convert SQL to csv first, and then use php's filesystem to read each line to extract and store as xml nodes OR does someone know easier/better method? Any help much appreciated, thanks. PHP date and time function is not showing correct time on my local system I have the following php code date_default_timezone_set("Africa/Lagos"); $date = date('d-m-y h:i:s'); echo "Server Time ".$date ."<br>"; echo "The time is " . date("h:i:sa")."<br>"; $current_datetime = date("Y-m-d") . ' ' . date("H:i:s", STRTOTIME(date('h:i:sa'))); echo "Current time1: ".$current_datetime . "<br>";
Output
Server Time 21-05-21 09:55:39
Expected Output
Server Time 21-05-21 10:55:39
Any help would be appreciated. Edited May 21 by Ponel I don't really know how to explain this, I saw once on some forum members signature, something like this : G = "\ x50 \ x72 \ 157 \ 144 \ x75 \ x63 \ 164 \ x20 \ x6c \ x69 \ 143 \ 145 \ 156 \ x73 \ 145 \ 040 \ x68 \ 141 \ x73 \ 040 \ x65 \ x78 \ 160 \. 151 \ 162 \ x65 \ 144 \ x2e \ x20 "+ E. That somehow translates into words, I know there is a PHP function to convert that, what is that code called and what is the PHP function? Good evening, I hope some of you can bring me some hope to solve this problem. My client wants to create pdf files and let the user download it. He want's to design one word file and then import it to the application. After that the portal users can request it, which means that the application should take the word file, search and replace some keywords and then create the pdf file for download purposes. I see fpdf but this class only create pdf's. We can not convert from word or even search and replace in one pdf file. There is any solution that i can use bear in mind that our application is located in external servers? Looking forward for your help. Regards, HS I've been looking at converting my php timestamps to display as month, day, and the hour and minute the event occurred on, i tried; Code: [Select] $time = date("j/n H:i", $Events['timestamp']); But no success can anyone point me in the correct direction? Thanks Hi all, Hopefully this will be a simple one for all you geniuses...Geniea... clever people out there. :? I'm trying to convert the following code from a mysql_ to sqlsrv_ statement. I have to admit i am a bit of a noob, but am learning fast! The code was originally developed by dreamweaver with some webassist extensions. $conn4 = sqlsrv_connect($hostname, $connectionInfo); if (!session_id()) session_start(); $insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1); $WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")"; $MM_editCmd = sqlsrv_query($conn4, $WA_Sql) or die(print_r( sqlsrv_errors(), true)); $_SESSION[$WA_sessionName] = sqlsrv_insert_id(); if ($WA_redirectURL != "") { if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) { $WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"]; } I appear to have had some luck with other parts of the code renaming mysql_ statements with the appropriate sqlsrv variations and some (slight) code re-hashing, but the above has given me a bit of a headache :banghead: . I assume that I need to break the "$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";" into two parts to give the sqlsrv_query it's `resource`, `array`, `parameter` format (I think that's right!), but i might be wrong. If it's all completely wrong, I apologise! Unfortunately due to the nature of the project Microsoft SQL is a necessary evil, and PDO has been considered but my brain is exploding with a (near straight) conversion as is... Unless anyone knows of a mysql to PDO conversion utility....or really easy method??? Would anyone be kind enough to help me with this? Regards Paladindc "In an ideal world, there would be no ideals, therefore would it indeed be ideal?" - Me Hello Freaks, Is there any possible way to convert a .PDF file to .html file without using any third party app and API?. I need That conversion fully made by PHP. Because i want to have full control on that conversion Help me with your opinion.. Thank You
Hello, Doing a little calendar where days are incremented as variable $i formatted like 'j' or single digit numbers 1,2,3 etc. (The calendar works fine) However for querying DB tables I need the day formatted as 'd' or 01,02,03 etc. so on any day I need to make this conversion. I can't find an easy solution though there must be one. Thanks in advance. Code: [Select] <?php //test day $i=7; $day=date('d', mktime($i)); echo "$day"; //Should be 07 ?> Can someone tell me how to convert a MySQL date such as 2010-08-13 into the the US format, such as 8/13/2010, and also the reverse using PHP? I can't seem to find the right functions. Thanks! I need a little help. I am trying to convert images taken from an upload form and convert them to jpg and then upload it to my directory. I tried GD but I cant figure out how to upload the converted file. I also tried using ffmpeg to convert the file but I am only able to do it with videos, I cant find the parameters for image to image conversion. Any input would be appreciated. Thanks I am writing a script to read a mail box and fetch mail body using php function "imap_fetchbody". If mail content encoding is UTF-8 then no problem but mail send from IPAd having ascii encoding and replace the new line with =20 along with many other changes. can anyone help me out with this in converting it to UTF-8 ?? Hi; I'm a beginner and I'm getting a big headache figuring how to convert php variables into Javascript variables. I want to use the content of $theName as the value for an input tag. $_SESSION['$Sess_Name'] is loaded with the right data, I verified it. But my function InitField returns always the word NULL. Why is that? Where is the problem? Thank Here is my code: function InitField() { <?php Hi, I am using a php script for converting avi,mpeg files to flv with ffmpeg.my code is Code: [Select] $srcFile = "uploads/flame.avi"; $destFile = "uploads/flame.flv"; $ffmpegPath = "/usr/bin/ffmpeg"; $flvtool2Path = "/usr/bin/flvtool2"; $ffmpegObj = new ffmpeg_movie($srcFile); $srcWidth = 320; $srcHeight = 240; $command = $ffmpegPath . " -i " . $srcFile . " -f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile . " | " . $flvtool2Path . " -U stdin " . $destFile; $convert = exec($command); if(!$convert) { echo "FAILED!!!"; } else { echo "SUCCESS"; }I can create a flv file using this script.But sometimes it creates a flv file with size 0 k.I don't know why this is happening.With the same avi file,sometimes it creates correct flv file and sometimes flv with size 0k.How can I confirm whether the conversion is success. In both the cases it displays SUCCESS. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342991.0 //$start_point = '2014-07-22'; $lastday = date('t',strtotime($start_point)); $month_val = date('n',strtotime($start_point)); echo "Last day: ". $lastday . "<br/>"; echo "Month: ". $month_val . "<br/>";I have a problem with a date value read from a MySQL database table into a PHP variable but when manipulating the vale to determine the month of the date, unexpected results appear. I am not sure what causes this but I suspect PHP is not properly handling date to string conversion. The output from the code shows 1 as the month when it should be 7. Hower the line of code with the comment "//$start_point = '2014-07-22' if added in give the correct result. When the value of the variable "start_point" is printed, it gives the value "2014-07-22". Please see the code Telly Hi all I've got an issue with time zones for displaying information. I'm hoping someone might know of a guide that would cover the following. I'm struggling to find one! Basically I have many online events to list in many different timezones. Users may wish to use their time zone to display information in. What I would like to do is store a timestamp and timezone for each event, then will need (I think!) to convert all to a single timezone in order to list them chronologically. From that I would then convert them into the user's desired timezone and display to the page. The idea to is avoid changes in time throughout the year, so it does it all automatically. Any links, tips, words of advice very gratefully received! |