Convert Mysql Datetime Into Something More Friendly
In an effort to do things "right" I'm now using a datatype of "datetime" in my mysql tables when they contain dates and times - I use to use varchar.
Problem is, when I pull this information out from the db for screen display, my current client freaks.
Instead of the current display of 2006-03-02 19:13:37, he wants it to show March 2, 2006, 7:28pm.
Easy, of course, when I was just using string data... but now, oh, no.
How does one go about converting an accurate datetime type to something like the above?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Using PHP With MySQL Datetime
I'm using PHP with MySQL 4.x and was having trouble converting a datetime from MySQL into a formatted string until I ran across this solution that converts a YYYY-MM-DD HH:MM:SS string into a Unix-style timestamp and then formats it. $timestamp = "2005-04-06 15:43:34"; $time = strtotime($timestamp); print date('Y-m-d a H:i', $time)." "; However, it seems kind of counter productive. After all, aren't people (and RDBMs like MySQL) getting away from Unix timestamps for the a reason? I don't necessarily think that my code will last until the 2038 timestamp rollover but I would rather avoid timestamps if possible and am surprised that PHP doesn't seem to offer a better solution - like parsing the string into some sort of date object or array, and then formatting THAT into the desired string. Is there such a thing right now? It looks like date_parse() is a step in the right direction (http://php.net/manual/en/function.date-parse.php) but it looks like it is not available in a snapshot release and that's only half of the equation anyway. I could always write my own function to do what I am after but I would like to use something built in if possible. Any ideas?
How To Check MySQL Datetime
I have a MySQL table with a datetime field. I know that I can select items from only this month when I use this SQL (embeded in PHP ofcourse): SELECT log_id FROM log WHERE MONTH(NOW()) - MONTH(log_date) >= Ƈ' Now what I want to do is to use PHP to check if a selected MySQL record is from this month. If it is, I want to display a form. If it isn't, I want it to display a message. What PHP code must I use to run this check? Can you help me out?
MySQL DATETIME And PHP Dates
Is there an easy way of formatting a MySQL DATETIME field in PHP. At the moment I'm using the code below, as using the returned DATETIME value from the database with the date() function doesn't seem to work. I know I could use the MySQL function date_format to format it before its returned but I use a simply query (e.g. SELECT * FROM TABLE WHERE colum = '$somevalue') and a while loop to read all the variables in, so I don't think I can format it before its returned. $date1 = "2005-04-12 20:45:54"; $date_array = explode("-", $date1); $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2]; $day = $day[0].$day[1]; $ts = mktime(0,0,0,$month, $day, $year); $dateVal = date("j-M-y", $ts); echo "<br>Date is: ".$dateVal;
Formating Mysql Datetime
I have a variable $dateTime which is set from a mysql query. The value will always be datetime as that is how the mysql column is set. I want to change the formating of the variable to return a value like august 19 at 3:30 pm.
Question About Datetime Column In Mysql
i tried this question in the mysql group, but have not heard anything. i have a database with about 20 tables. The some of these tables have datetime type columns in them. What i am basically wondering is if there is a way to make a default value of now() apply if it is not specified when the row is created. i know this is possible with a timestamp, but is it possible with a datetime column ? and if so, how ?
Fastest Way To Format MySQL DATETIME In PHP 5
You've got a MySQL DATETIME string that you pull out of the db as a variable. Why? Because you're cool. And, because this DATETIME is so hot right now. Our DATETIME looks like: 2007-10-13 03:47:05 But you want it to take off its clothes and get it to look like: 3:47:05 ================================================= What line(s) would you use on this skanky little DATETIME to get it how you want it? Its the speed that's key here, boys. We all know you can pull out and use a lame ass substring function. But we should all be above that by now.
MySQL Datetime Field Default Now() Fails
I have a mySQL database table with a column field datatype of datetime that I set up in the original create table statement like this: create table nnet_usermetadata ( .... nnet_record_entered datetime default 'now()' ) However, upon execution, each time a record is entered into nnet_usermetadata the results are: 00-00-0000 00:00:00 Is there a way I can always ensure that the current date and time are always entered into the datetime field?
Need To Convert Mysql To Excel?
I need to display data from MySQL to Excel format. I looked at several excel classes, but they are missing three things that I need. 1. To be able to output a cell larger than 255 characters. 2. Be able to keep line breaks in cells. 3. be able to format the cell widths I am currently using a tab delimited set up with excel http headers, but I can not format the cell widths.
Convert MySQL Results To XML
I just got Dreamweaver CS3, and I love the built in SPRY framework. It allows you to create web applications that use a table listing, and details listing very quickly. Unfortunately the only data the SPRY framework can accept is XML. Is there a built in function to convert from a $row result from MySQL to XML? Code:
Convert Isnull From SQLServer To MySQL
In a program, I work with SQLServer and MySql. In a particular select, for SQLServer, I have something like this: SELECT ISNULL(field,0) FROM TABLE. If the field is not null, returns its value; otherwise, 0. I have found isnull for MySQL, but it does not work exactly the same way. Any idea to convert that isnull from SQLServer to MySQL?
I Need To Convert Some Chars Before Submitting To MySQL
I'm putting up a website, related to an IRC roleplaying channel, where my players can register their RP-characters in a SQL database, and will afterwards be able to log in, and alter the information they have submitted (name, age, description, sex, etc). My problem: The players will also submit their IRC nick they use while playing. This produces a problem for me, because IRC nicks can and often do contain special chars like [,],{,} as well as `and . So, whenever I submit a name containing a [ or ], it is read as nothing, and since the registration code requires that particular field to be filled in, it aborts the registration. What I need: ...is some kind of code which will allow me to submit these characters, and put them into my SQL database. A reference to reading the PHP manual won't do much good, because I know too little about PHP programming (the authorization system I'm using is that of Tim Perdue's at PHPBuilder.com. You can find the whole system here). I'm also having problems with sentences like "...and it's some kind of..." turning up like "...and it's some kind of..." when I retrieve the data from the database and display it as HTML.
Can I Convert MySQL Db Records Into Microsoft Word Documents?
i found the solution to export file from mysql db into *.csv. but is there anyway to convert the contents into *.doc and save in my webserver and providing a link for the end users to download the word file? FYI, the database records are obtained by end users submitting the forms themselve and i saved it in my db...
How To Convert Carriage Return In Mysql To Excel Format?
I have a varchar field in MySQL table that has carriage returns. I am trying to display this field in an Excel document. When I display this using (php_writeexcel class ) Excel I get small squares due to Excel converting the carriage returns. Is there a way to convert these carriage returns to display properly. I have already tried str_replace("","",$value) and does not work. Any regular expressions?
Date_FORMAT Need To Convert Back To MySQL Date Format
Below is a couple of snippets of code that I have for modifying the date format from MySQL and it works great. The problem I am running into is later in the code I need to call the $AuctionDate variable to query the data field in another table. This won't work because the format has been modified using date_FORMAT. How do I convert it back to the MySQL date format so I can properly query the database. Code:
Portal SE Friendly
Does anybody know a free php portal system that is also Search Engine friendly meaning that it can be configured not to show unfriendly URL to search engine spiders?
Printer Friendly?
Can someone tell me where the printer friendly version of the PHP documentation is located now?
Is The Filext .php A Must? And Is It SE Friendly?
Is it a requirement to name any PHP file of a web page with the .php extension, in the form of index.php, for instance? Or can you name the file index.htm, even though it has <?php...?> code in it, and it would still work? I tested this index.htm file that has PHP code in it on my own computer, and it worked, or the page showed correctly. But when I uploaded the file to my website server, named with an .htm extension, it did not display correctly. Is there something wrong with the server, to which I have to draw the administrator's attention? Also, if the file is named index.php, is it still possible to only give people the www.example.com part without the /index.php, and the browser would show the website normally? I'm asking because I know that as long as the file after the slash / is called index.htm or index.html, then you don't have to include the index.htm part in the address, which makes whichever address you're giving look nicer and easier to remember. But when I tried going to a certain address without putting the index.PHP part, it didn't work. So, again, does the administrator of the website server or host have to do something to make this work with index.php files just as it works with index.htm files? Are PHP files search-engine friendly? I know that a lot of the code inside a php file sometimes simply embeds X/HTML code into the page before sending it to the client, but generally speaking, are there any caveats, related to search engines, of which to be aware when all the pages in a website are PHP? For instance, is it a problem that the raw .php file does not have any "content", and it gets all the content from certain other .php or .htm files? Finally, I heard of a certain method, which makes all the addresses within any website search-engine, bookmark, AND linking friendly, i.e., it gives you the ability to have a certain fixed URI for every item in your website, regardless of its file extension. And if someone had bookmarked a certain page in your site one year ago, but you changed the technology you use or something, then no one ends up with linkrot. What is this method exactly and where can I learn its implementation?
Friendly Ursl
for some time now i've been using this so called "technique" to provide my web site visitors with friendly urls. example, when a user visits: PHP Code:
Spider Friendly URL's
I know I've seen tutorials on this kind of thing before, but now that I'm ready to do it I can't find one. I know it has something to do with editing the conf file....can anyone point me in the right direction? I figured out how to change the title tag dynamically so now search engines would see different tags if they could just spider my pages such as http://321webmaster.com/index.php?cat_id=3&subcat_id=79
SEO Friendly URLs Without .htaccess
I want to display search engine friendly URLs, but I don't have access to a .htaccess file (Yahoo!, what the heck?!?!?). Is there another way? If so, can anyone point me in the right direction?
Drop Down Menu Web TV Friendly
i am currently the owner of a game and some of my players cant access all the pages in the game because they cant see the drop down menu as they are using web tv. Code:
PHP's Urlencode() = Create Friendly URL?
I use urlencode() to encode my URL that I want friendly to search engines. The result is something like: http/www.example.com/word1+word2+word3/word4 Is the plus sign "+" a good delimiter for words? Will Google and other search engins see "word1", "word2" and "word3" as separated words? Should I use "-" or "_" instead?
Search Engine Friendly URLs
I've been trying to use .htaccess to get Apache to recognise 'article' as 'article.php' so I can have search engine friendly urls in the form article/var1/var2/var3 etc I have this in a .htaccess file <Files article> ForceType application/x-httpd-php </Files> This works fine on my test server but for some reason my host server (choice is out of my control) will not allow me to upload a .htaccess file. Is there another way of doing it?
How To Open New (printer-friendly) Window
I have a php script that presents a rather simple form. After the user filled in parameters and presses <submit>, the results from a postgres database search follows on the page. Now, if the user wishes to print the page, it'll be ugly containing the form boxes. So one solution would be to present a "printer-friendly" option on the page. Clicking there will present the results in a new window free from the form boxes. I don't want to repeat the database search in this new window, just "forward" the variables to this new url.
Search Engine Friendly URLs
I am developing a Blog system. I am doing it for two reasons : 1) To Learn more about PHP 2) Wordpress and other systems are too sophisticated for me. I need some help in getting Search Engine friendly URLs. For eg, I have a Post's title as "A New Post". That is entered into one field of the DB. I want to insert into another field as "a-new-post" so that i can use it in URLs. Could anyone advice me how to do it ? Also what can be done if the Title contains some special characters.
Search Engine Friendly URLS On WinNT/IIS
I'm trying to make my dynamic php pages search engine friendly. I've searched these forums and read the article on Sitepoint, but all of those talk about make the URLs search engine friendly on servers running Apache. Here at the office we have a Windows NT server running IIS rather than Apache, and I can't find a way to get the URLs to be search engine friendly. Does anyone have any ideas on what I could do to make my dynamic php pages search engine friendly?
Exc Handling And User Friendly, Secure ErrMsgs
In my efforts to design a good Database layer, I've used exceptions and wanted to implement best practices for this project. Obviously an uncaught exception creates a Fatal Error and stops execution. Currently, I see the best scenario, as: if there is an error in the DB layer, throw a DBexc which effectively, logs all SQL and problem info. In the catch block, throw a general error, with a more generic statement, and possibly include a logging ID or # with it. ( avoids sending SQL statements to the screen ) Does this sound sensible, or the best way to do this ? other options ? is is common to use set_error_handler ? What about recovery ? does execution have to terminate ? I'm also interested in programming this system, with security in mind, ie: avoid SQL injection. I haven't researched it fully, but I have seen posts, reccommending addslashes(), etc. I'm using PEAR::DB, and looking forward to any responses.
Which Tool (written In PHP) To Deal With Db By Interface Friendly (like Access)?
I'd like to deal (update, deal, insert....) a database (with tables and relationship between these) by a tool written in php. I need to share and work on a database with other people. I'd like to find an interface like microsoft access interface or that let manipulate the db in easy vay. Which tool can I use? Or wich libray can I use for write this tool by myself (in PHP)?
Sending Page To PHP Script That Forms It Into Printer Friendly Format....
How would one go about enclosing the certain elements of a page (specifying them as variables maybe) and sending them to a specific PHP script (if can be done by a PHP script) so when the viewer clicks on the link "printer friendly version" or something of a specific page it sends that data to a PHP file (e.g. printpage.php3) and forms it into text only printable content? Also, how would I go about creating the code for the "printpage.php3" or whatever?
Datetime
The following might be either PHP or MySQL question: How can I calculate the diffirence in HOURS between two values in DATETIME format?
Datetime
I have a table which have a datetime column. When I touch (update, Insert) a row in the table I would like to update the value of the datetime column. How do I do that? I have tried to use the function now() but MySQL doesn't seem to support this function. Does php have a function I can use for capturering the servertime?
Datetime
So I have a certain date in a table (and the type of field is datetime), what code would show what that date would be in 7 days? I'm having each row expire after 7 days, and I want to be able to make a countdown of how many days/hours/minutes are left until it expires.
Datetime
i put a datetime column in my mysql table what php code do i need to get the time and add it into the table?
Sql Datetime Problem
alright the problem i am having is i want to keep track of the days a person has been signed up for something. so i use this code...
Datetime Problem
I have a field called "LastUpdate" in a MySql table which is of type "datetime". Whenever that record is updated , i want to insert curent date and time in that field..like 2003-09-24 12:03:03 How can it be done?
Datetime Query
I am trying to insert the following query into a table field called last_login it does not seem to be updating the time the user logged in, the field type I am using is datetime on my table. $nowtime = mktime(date(G),date(i),0,date("m"),date("d"),date("Y")); $auth_query = mysql_query("select * from $dbtable where username='$user' and password='$pass' and last_login > '$nowtime'") or die("Could not execute query auth_query"); } if (mysql_num_rows($auth_query) == "0") { $timeout = mktime(date(G),date(i)+10,0,date("m"),date("d"),date("Y")); mysql_query("update $dbtable set last_login='$timeout' where username='$user' and password='$pass'") or die("Could not execute query"); }
Splitting Datetime
Im trying to split a datetime string. I can to it with the date but it is giving me problems with the time: $tourney[enddate] = the date $tourney[enddatetime] = date and time This is what i did with just the date: PHP Code:
GROUP BY On A DATETIME
Is there an MySQL query to group data on year-month using datetime(YYYY-MM-DD HH:MM:SS)?
Add 16 Hours To Datetime
I have a mysql database table that gets the "datetime" column automatically filled when a user fills in the php form page. $curdate = date("Y-m-d H:i:s"); Trouble is, the database server is in the USA which is 16 hours behind my time. Does anyone know a way to change this so that the 16 hours get added to the datetime?
Inserting DateTime
I am receiving an Internal Error Message when I try to insert datetime into a datetime field. My script looks like this: $EnrolledDate = date("Y-m-d"); $AllottedTime = 3.00; $AccumulatedTime = 0.00; $Email = "vtaylor157@aol.com"; $ItemNo = 154327; Code:
DATETIME Conversion
I am having trouble with this error: PHP Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft OLE DB Provider for SQL Server Description: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. In my MSSQL database I have field(pub_date) of type varchar which stores date in January 1, 2007 format. In my php page user selects two dates (which are also in the format January 1, 2007) and I have to o/p the records from the database between those two dates. I am writing a query to do that as "SELECT * FROM table WHERE (CAST(pub_date AS DATETIME) BETWEEN '$fromdate' AND '$todate'". Before when I was not using CAST I have not got the expected results when user chooses fromdate= May 1, 2007 and todate = June 10, 2007, which is may be because my field is a varchar and char J < char M. Now, when I am using CAST...it gives me results but it is also giving me the above error. I would like to know if there is any other way that I can use without getting this error.
Subtracting Datetime
If I want to display a message saying "Ready" if the $datemade variable is more than 48 hours ago but $datemade is stored as a datetime in the database how would I do it? I can create the code using strtotime("-2 days") and it works to see if the $datemade is more or less than 2 days but I cannot get it to show how many hours are left. Basically, if ($datemade > 48 hours){ echo "Ready"; } else { echo $hours . "hours " . $mins . "mins remaining until ready."; }
DATETIME Output
so into my database, one table goes in DATETIME with default format being: 0000-00-00 00:00:00. When I output, how can I convert this to something like - 06/12/99 @ 12:00PM or even - June 21st, 1987 @ 12:00PM ??
Datetime Function
I just started to build a simple forum application.in my postreply.php I set things like this: $postDate = date("D M d,Y H:i:s"); $postTime = date("U"); $userID = $User["UserID"]; // And add the new message to the Post table $query = "INSERT INTO masterpost (parent_thread, in_reply_to, author, body, time_post, time_elapsed, userID) "; $query .= "VALUES( "; $query .= $thread['parent_thread'] . ","; $query .= $_POST['freplyto'] . ","; $query .= "'$author',"; $query .= "'$body',"; $query .= "'$postDate',"; and then I would insert this record to my database and I display it with order by time_post,But when I want to display it,my placement is all messed up, eventhough it was ordered by time_post. After I read an reread my codes,I think I find the culprit. I think it's because I used date() function.So,it got local time and not my server time. My question is,is there other ways to record the datetime in php?
|