PHP - Now (), Datetime & Varchar Scramble
Hello,
I have a query that displays a list of events for the year, and am in need of guidance on how to have it only show events that are >= today's date. The 'date' is inserted into the table as a varchar field from javascript code. There was an old blog post about doing something like.... Code: [Select] SELECT * FROM calendar WHERE `date` >= NOW() ORDER BY date ASC LIMIT 5 I seem to have trouble in that i believe NOW() will only work with proper datetime entries as opposed to my varchar setup. any help navigating this would be great. Similar TutorialsDear all, how can I convert a string "yyyy-mm-dd hh:mm" into a really datetime value with php? thanks! My DB has fields that primarily record numeric values. I've noticed that a NUMBER in a VARCHAR field is aligned to the right and will hold decimal places, and a SMALLINT seems to align left and strip whole numbers to the bare digit (eg.: 4.0 is held to 4). What's the best way for me to store values, if I want them to hold at least ONE decimal place (so that whole numbers line up EVENLY with fractions: 1.0 1.5 2.0 etc? Is there a way to "adjust" a setting within MySQL? Or in the query that pulls the info? need your suggestion here is my problem i have field varchar(1000) in my sql server 2008 DB but if i mssql_fetch_object($result) my field value truncated and only show 256 character, why ? in my DB . my field value really 1000 character long . I am not a developer and am learning so forgive lack of what may be obvious knowledge to you folks.
Our hosting provider has upgraded our version of SQL 5.7.7 which sets the default SQL mode to strict. As strict mode controls how MySQL handles invalid or missing values in data-change statements such as INSERT or UPDATE we now have an error with some of our old PHP code. We are trying to insert a timestamp as follows
$insertSQL = sprintf("INSERT INTO tournaments (tourn_id, tourn_name, tourn_year, site_visible, tourn_type, ranking_type, tourn_class, how_seed, status) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", But we now get an error stating "Column tourn_year cannot be null"
The hosting provider has stated that since MySQL version 5.7.7 the default sql_mode is strict a value is missing when a new row to be inserted does not contain a value for a non-NULL column that has no explicit DEFAULT clause in its definition. As specified in https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-strict I am wondering what is the easiest least impactful way to fix this. Do I change to varchar (see image) or change the code? Thanks for your help in advance
how would i add text onto the end of a varchar field? i have tried using update like so: mysqli_query($link, "UPDATE ".TBL_PREFIX."posts SET post_likes = post_likes + ', $qu' WHERE post_id = '$post_id' ")or die(mysqli_error($link)); but that set the table to 0. Any ideas? I have a registration form and there is a part for Phone Numbers / Email it's option for either. My question is : The Field is a VARCHAR 255 , the max you can input on that registration field is 20 Characters? HOW Can i change the value to more like 30 - 40 characters ? please help. Jelly Bellys. So there are "recipes" of ones you can eat at the same time. The most well-known one is probably mixing a couple peanut butter jelly beans with a couple grapes. I have to say it's pretty good because they actually do taste like peanut butter and grapes, but I have one issue: the peanut butter flavor is too weak compared to the grape. Instead of a 1-1 ratio it takes more like 3-1. Weird thing, this has got to be the most famous recipe so why isn't it listed on their site? I see candy apple, tiramisu, and lemon meringue pie, but nothing about peanut butter and jelly sandwiches. Are they just not popular anymore? Personally I prefer peanut butter and chocolate (Nutella, specifically) but whatever. Which can't be that weird because Reese's is popular... Mind you peanut butter + Nutella sandwiches don't really taste like Reese's candies, but that could just be because of the type of chocolate. Like they use milk or dark chocolate while Nutella is based on hazelnut. Which reminds me, I have a jar of it in the cupboard, but it's been so long since I've used it that it might have turned into an oily mess by now. I know it's just the various oils and such separating but it looks like someone poured a teaspoon or two of water right into it and that just kinda puts me off the whole thing. Same for peanut butter for that matter except the "water" isn't clear. Dirty water. And mixing everything back together isn't so bad but it gets the knife dirty on the handle, which really bothers me because then my fingers get dirty and I have to stop what I'm doing and go wash my hands. I already do that enough each day, I don't want to make more reasons for me to do so. But beyond the oily mess there's also stuff getting stale. Stale Nutella is a pain because it's stiff and hard to deal with, and the kind of bread I like most is very soft and easily rips apart so spreading it on can be a real labor. Best method I've found is to spread a little bit on at a time but it takes so long to cover the whole face. Fine, it's a good sandwich, but in that same time I could have done something else. Maybe there's something in the freezer I could quickly heat up, or maybe there's some leftovers in the fridge I could eat. And if not there's pretty good odds that I need to go to the grocery store anyways. Ah, sorry. Forgot why I'm here. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=358112.0 hi there..im new to php mysql and im having trouble inserting a string data to mysql from a php date() function. here's my code: Code: [Select] $year = date('Y'); echo $year; $insertSQL = sprintf("INSERT INTO tbl_elections (election_id=$year)"); mysql_select_db($database_organizazone_db, $organizazone_db); $Result1 = mysql_query($insertSQL, $organizazone_db) or die(mysql_error()); when i try to output the $year variable on a webpage, it returns "2012" but when i try to insert this data into my database table, it returns an error like this: check the manual that corresponds to your MySQL server version for the right syntax to use near '=2012)' is there a way to convert "2012" into a normal string data type? I have a varchar field called date that looks like this "2/06/2011 TUE" or like this "10/05/2011 WED". When I do an Order BY date Desc in php it does Not sort properly. Thanks for your assistance Steve 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 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 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, 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 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.
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?? 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? 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> 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'); }
|