PHP - Datetime Format
Hello!! i want to save datetimes into a mysql database. Their format is dd-mm-yy hh:mm. I think mysql format for datetime is yy-mm-dd hh:mm..How can i convert them??
Similar TutorialsI have multiple datetimes. The format is dd-mm-yy, hh:mm. I want to insert it into a table using mysql. However mysql format is yy-mm-dd, hh:mm:ss. How can i do it and what type should i use (datetime?timestamp?). Thanks for your help!! I have a field called date_time in the database which is of type datetime. I have a form which on submit needs to enter the current date and time in the date_time field. I know I can get the current time using time() $time=time(); Can do I do some kind of manipulation using strtotime() and store in the database in datetime format? Dear all, how can I convert a string "yyyy-mm-dd hh:mm" into a really datetime value with php? thanks!
Hello All, function convertTimeFormat($time12Hour) { // Initialized required variable to an empty string. $time24Hour = ""; // Used explode() function to break the string into an array and stored its value in $Split variable. $Split = explode(":",$time12Hour); // print_r(explode (":", $time12Hour)); => Array ( [0] => 09 [1] => 50 [2] => 08AM ) // Retrieved only "hour" from the array and stored in $Hour variable. $Hour = $Split[0]; $Split[2] = substr($Split[2],0,2); // Used stripos() function to find the position of the first occurrence of a string inside another string. if($Hour == '12' && strpos($time12Hour,"AM")!== FALSE) { // Code here } elseif(strpos($time12Hour,"PM")!== FALSE && $Hour != "12") { // code here } return $time24Hour; } $time12Hour = "09:50:08AM"; $result = convertTimeFormat($time12Hour); print_r($result); /* Input : "09:50:08AM"; Output : "21:50:08PM"; */
Hi all, I am currently making a website that has e-custom functions and a back end for the client. I want them to be able to upload images - but they need to be transparent. I do not want to leave this in the hands of the client, so I am looking at ways of using the GD library to make the change I got no issue with the png/gif type for upload/resize function since this type already transparent background but my major problems is how to deal with jpeg/jpg image type which is their background was not a transparent...so is it possible I can change/ convert to png/gif type upon successful of uploading image...so the new final image will be png/gif type with transparent background...is it doable...I am not even sure it is possible...? Thanks for any help.. Hello All, I have the following code: Code: [Select] echo "<table width='615px' cellpadding='3' cellspacing='4' align='center'>"; echo "<tr>"; echo "<td align='left' width='150px'>"; echo substr($row['date'],0,11); echo "</td>"; echo "<td align='left' width='465px'>"; echo $row["food"] ; echo "</td>"; echo "</tr>"; echo "</table>"; And this outputs: Apr 4 2011 Chicken Ceasar Salad, Garlic Toast, Cloddhoppers, Applesauce, & Milk (etc.) How can I add "Mon" in front of "Apr 4 2011"? thanks! This code gives me 1969-12-31 18:33:30 Code: [Select] <?=date('d M Y', $val['Created']);?> and this one gives me 2010-11-04 03:52:54 WHICH IS THE RIGHT ONE - BUT i need to format as above. Code: [Select] <?=$val['Created']?> this happens on the same line of code. What is wrong? Hi, I'm a newbie here, and with PHP, and need some help with the datetime display. I am wanting to utilize old Naval comms DTG (datetimegroup) format which is DDHHMM 3-digit Month 2-digit year. The DDHHMM = Day (01 - 31) HH (hour 01 - 24) MM (minute 00 - 59) What I need to do is to add the letter Z (meaning GMT, ZULU) like thus DDHHMMZ FEB 11 How can I go about inserting that Z into this? Tks in advance for any assist Code: [Select] OFXAdapter: Failed to parse request: Unable to parse an atomic field "OFXRequest.OFXRequest.SignOnMsgsRqUn.SignOnMsgsRqV1.SonRq.DtClient": field value "20101005091544.000[-4:EDT]" is not a valid (YYYYMMDDHHMMSS.XXX[gmt offset:tz name]) date. I am trying to put together some PHP code to use the OFX standard to communicate with my bank in order to download my recent transactions. The standard details that in the sign-on request, the date and time must be included in the format listed above. As you can see, I have the value in the exact same format as specified. So my question is this: is there something about GMT offset or TZ names that I am missing here? Hey, does anybody know a good function, where I can have the trendy "time ago" functionality?
A good tutorial would be cool, too.
I would be using the datetime function off MySQL.
Basically I am using DATETIME to store the time in which a row was input. Format - 2010-11-13 21:31:53 How would I get the current time of page load and compare it to the database row "2010-11-13 21:31:53" then output the difference. Example $sqlresult = 2010-11-13 21:31:53; $currentTime = (GET CURRENT DATE+TIME = (2010-11-13 21:31:55) ); Output - This was posted 2 minute's ago. Thank you in advance. Any help would be greatly appreciated. Hi Everyone, Please have a look at this, and tell me if its right? I am generating a sitemap for my website dynamically. The date I am providing: 2012-02-24 11:56:09 and this is the output I am getting: 2012-02-24T11:56:09Z now I am not sure of the Z at the end of the returned value. I think I am looking for something similar to this: 2012-03-12T12:00:02+02:00 not to sure what I am doing wrong and where it gets the timezone from, I am guessing from the php config file. any help would be much appreciated. thanks My code: Code: [Select] <lastmod><?php echo $time->toAtom($post['Post']['modified']); ?></lastmod> I'm given something like this: Sun Nov 06 2011 09:30:00 GMT-0500 (EST) And i'm trying to turn that into 2011-11-06 09:30:00 I started by using explode and trying to loop through the day and month to figure it out, but that seems inefficient and overly complicated. Am i missing something? Thanks I have a function that receives two datetime values attached to the variables $start and $end. These will be in the format 'Y-m-d H:i:s'. For each of these values, I create a DateTime object to make the handling of them easier: Code: [Select] $startDT = DateTime::createFromFormat('Y-m-d H:i:s', $start); $endDT = DateTime::createFromFormat('Y-m-d H:i:s', $end); What I need to do now is ensure that the seconds of the $startDT value are always set to '00' and the seconds of the $endDT value are always set to '59'. Is there an easy way to do this without having to extract the individual values for hours, minutes and seconds before reapplying them using the setTime function, adjusting the values accordingly? Hello, I am trying create a news article, but I have few category in it. Can you help me to create an "add article form" which has dropdown list of category that I can choose, so when I select "Announcement" it will save the data on my mysql database under announcement table. sample html form below. <form id="form1" name="form1" method="post" action=""> <label> Category : <select name="category" id="category"> <option>--- choose category ---</option> <option>News</option> <option>Announcement</option> <option>Sports</option> </select> </label> <br /> Date: <br /> Title: <label> <input type="text" name="title" id="title" /> </label> <br /> Body: <label> <textarea name="body" id="body" cols="45" rows="5"></textarea> </label> <br /> <label> <input type="submit" name="Submit" id="Submit" value="Submit" /> </label> <br /> <br /> </form> Can you tell me how to create the php code which support the above html. Also, I would like to have a date and time on my article, but I want it automatically get the time and date from the computer of the client, so the user will not put it manually. can you point me to the correct code? Thanks and hope you can help me! I am trying to import into a csv file and filter the results to a particular user and only results based on the time the data was uploaded within one hour. In other words anything not uploaded within the last hour of the start_time will not appear in the csv file. Everything works fine except for the time part. I get no results at all with the 'and unix_timestamp........ For all I know possibly I am way off with my effort. The field name is start_time. Here is code below. Appreciate any help.
<code> header('Content-type: application/csv'); </code> Hi all, I have a loop that is modifying a DateTime object. It goes through X number of times and adds 1 day to the date time object and stores the modified object in an array. I use ->add(new DateInterval('P1D')); For some reason it is losing an hour each time that I add a day. I start out at 19:00 and each iteration through the loop adds a day, but loses an hour. 2010-09-19 19:00:00 2010-09-20 18:00:00 2010-09-21 17:00:00 I can correct for this by doing ->add(new DateInterval('P1DT1H'));, but adding 25 hours instead of 24 hours doesn't make any sense to me. I am using PHP Version 5.3.1. Any ideas? Thanks, W It is my belief that when storing time in the DB, it should always be at UTC. Agree? My question is whether one should work with DateTimes with a specific time zone or only do so when displaying the time to the user? For example, if I have multiple users which have a timezone string property based on their physical location as well as a datatime property when some event occurred for the given user, and need to implement some logic if the event occurred more than a given duration from the current time, which of the following approaches should be used? $currentTime = new DateTimeImmutable(); $userEventTime = new DateTime($queryResults['theEventField']); if($currentTime->sub(new DateInterval('P10D')) < $userEventTime) { //Display time to the user $displayEventTime = new DateTime('@'.$userEventTime->getTimestamp(), new DateTimeZone($queryResults['userTimeZone']))->format('Y-m-d H:i:sP'); }
$currentTime = new DateTimeImmutable('now', new DateTimeZone($queryResults['userTimeZone'])); $userEventTime = new DateTime($queryResults['theEventField'], new DateTimeZone($queryResults['userTimeZone'])); if($currentTime->sub(new DateInterval('P10D')) < $userEventTime) { //Display time to the user $displayEventTime = $userEventTime->format('Y-m-d H:i:sP'); }
Hi, so I am trying to get how many minutes and seconds are left from the datetime entry in the database and the current datetime, but I'm having issues... Here's my code: Code: [Select] $query = "SELECT RequestMadeDateTime FROM TempAwaitingClients WHERE PSOID = '2'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $RequestMadeDateTime = $row['RequestMadeDateTime']; $currentDateTime = date('Y-m-d H:i:s'); echo 'Request Made Date Time: ' . $RequestMadeDateTime . '<br />'; echo 'Current Date Time: ' . $currentDateTime . '<br />'; echo date_diff($RequestMadeDateTime, $currentDateTime); What I'm getting those is this, "Warning: date_diff() expects parameter 1 to be DateTime" ... Which I don't get because both variables are DateTime... I am preparing $begin and $end for DatePeriod() but I can't get passed this error "getting the error Recoverable fatal error: Object of class DateTime could not be converted to string". $today = date("Y-m-d"); $datestop=$_POST['datestop']; //echo "$today<br /><br />$datestop<br /><br />"; $begin = new DateTime("$today"); $end = new DateTime("$datestop");
|