Displaying A Date With Strtotime
I have successfully used strtotime to format the date on a webpage that is
pulled form a MySQL database in the form yyyy-mm-dd.
However, in another part of the webpage, I have to insert another date that
may contain a NULL entry in the database. If I use strtotime to format this
then it enters the current date, whereas I want it left blank.
View Complete Forum Thread with Replies
Related Forum Messages:
Date Strtotime
i am trying to right a date into the mysql database but when i get the date from the html form and do strtotime on it it goes to an invalid date (by this i mean it is not the date i entered in the html form so for example 22-06-2007 changes to 28-11-2027).
View Replies !
Strtotime(date('m/d/Y'))
does the following code give the correct time:?strtotime(date('m/d/Y')) or do I need to use : strtotime(date('d/m/Y'))? I tried to find out which way the month and day work, but can't seem to find anything that will tell me.
View Replies !
Strtotime And A Very Mysterious Date
Namely the thirteenth of December 1901, 12:45:52, Pacific Time. All dates later than this passed in format "yyyy-mm-dd hh:mm:ss" to the strtotime function return the correct unix timestamp value (as can be verified by passing it back to date()). If a date earlier than 1901-12-13 12:45:52 is used, it returns an error. I tried this for a while to find the exact cut-off point, and this is it. Any reason - possibly a limitation of the integer value that is used? I didn't find this documented anywhere...
View Replies !
Use Strtotime To Convert A Date
I am trying to use strtotime to convert a date, gathered from a database, and add 21 days to the date. Example: Date from MySQL record is 2007-01-01 I need it to be echoed to the browser as 2007-01-22. Here is what I have now but it just outputs the database date without adding the 21 days. $requested = date('F jS, Y', strtotime($row['letter_requested'])); //Convert to letter requested date $sendBy = strtotime($requested, '+21 day'); echo $sendBy;
View Replies !
Strtotime And Date Functions
I'm trying to add 3 days to a stored starting date: echo $_SESSION['start_date']."<br>"; $new_timestamp = ($_SESSION['start_date'] + strtotime("+3 days")); $new_date = date('Y-m-d', $new_timestamp); echo $new_date; This ouputs: 2007-02-18 2007-02-25 (which is clearly + 7 days?) I would expect it to output: 2007-02-18 2007-02-21
View Replies !
More Date / Strtotime Confusion
I have an editable form, that (upon other things) retrieves a date from mysql. To prepopulate this text field, I use: $result = mysql_query("SELECT DATE_FORMAT(Expiration_Date, '%d-%b-%y') AS DateX FROM MyTable) or exit(mysql_error()); Which will return (for example): 01-Jan-06 I have a dropdown field that a user can use to select the number of days to add to this date. In addition, however, the user should also be allowed to opt to not use the dropdown, but type in the value instead, in the d-M-y format. Code:
View Replies !
Strtotime & Relative Date String
I thought something like this would work to get the next February after a specified date. $nextFebruary = strtotime( "next February", $unixDate ); However, if $unixDate corresponds to a date after February, I get the February before $unixDate instead of the February of the following year. I can, of course, check to see if $nextFebruary < $unixDate and, if it is, make sure I jump forward one year. But, I am thinking there is an easier way to accomplish this...as I cannot think of the method myself, I thought someone else might know.
View Replies !
Strtotime Returning Funky Date
I'm sure there's a better way to code this, and pointers would be greatly appreciated, but my immediate problem is figuring out how to return the correct date. Upon retrieving $date1 from the database, I format it like so: PHP Code:
View Replies !
Use The Strtotime Function To Converta Date
Im trying to use the strtotime function to convert this a date in this format ( 2007 11 11 20:34:56 ) to a unix timestamp. It should work (I think) but doesnt. What have I done wrong with the below code?? $date = strtotime($date); Thanks in advance. Eon201.
View Replies !
Problems With Strtotime()/date Comparison
I've a field in my database called CheckDate (type: date) in the format yyyy-mm-dd. I've 2 user inputs $start and $end in the format yyyy-mm-dd. I would like to check if the CheckDate is between the dates, $start and $end. Code:
View Replies !
Displaying Date
i'm working on K Yank's book and, at some point, i've an insert like this: $sql = "INSERT INTO Jokes SET ... JokeDate = CURDATE()"; When i dysplay this on my webpage, the date format is YYYY,MM,DD and in my country (Portugal), the format is day, month, year How can i achieve it?
View Replies !
Displaying Date...
As a final touch to my current project I am trying to display a "Last Updated: " field on the user profile pages of the website. The SQL database is updating the field last_updated automatically any time a record is altered, and this is working fine... Structure details from phpMyAdmin (in table 'users'): last_updated timestamp ON UPDATE CURRENT_TIMESTAMP No 0000-00-00 00:00:00 However when I try to output this date I get the result: Profile Updated: January 1, 1970 The code I am using is as follows... Code:
View Replies !
Displaying A Date
My current code: foreach ($page['events'] as $z) { echo '<b>', $z['date'], '</b></p>'; } Which is pulling "date" from a DATE field in the database. Would like it to display as 3-22-2007 ... instead of 2007-3-22 - I know theres a quick answer out there but cant find it.
View Replies !
Displaying A Date Range
I would like to display a user specified date range e.g Monday to Monday next week or maybe Monday next month. When I have the basic function worked out I would like to get Data from a Mysql Database. here is what I have thought about. Code:
View Replies !
Displaying DATE From Database?
I have a database field called `DATE` which has data type date. The purpose of `DATE` as you guessed is to store a date. 2007-11-31 I want to write a script to update a news article posting date. The only way to do this is to break DATE into three separate sections, $year, $month and $day How do I go about doing this? Please keep in mind, the date is already stored in the database, it does not need to be today's date. It can be any date! Lets work with 2007-11-31 as an example.
View Replies !
Displaying Date Format
if i have written a date to a database using CURDATE() and its in the format yyyy-mm-dd, is there a way i can then extract it from the database in another format, eg. dd-mm-yyyy?
View Replies !
Displaying A Date Before 1970
I am really struggling with displaying a date PRE 1970 in php and mysql. I have a date of birth field in my myqsl db and can echo it out without problem but because i need to echo it out in UK format (DD-MM-YYYY) I get 31 December 1969 on all dated previous to this date. This is the code I use to 'switch' the date around list($year, $month, $day)= explode("-", $date); $show_date=date(" d F Y", mktime(0,0,0,$month,$day,$year));
View Replies !
Displaying Date/time
I'd quite like to have a list of dates/times showin in different timezones i.e. China: 09:56:01PM, saturday 5 Feburary India: 01:56:01AM, saturday 5 Feburary Is there anyway I an do this on the fly using PHP without having to change any sort of timezone/server config variables?
View Replies !
Displaying Modified Date Of A URL File
I want to display a web page with links to various documents and display the date each document was last modified next to the link. I've found the filemtime command and that works quite nicely for "local" files. However, filemtime doesn't work if the file(s) are refered to by their URLs (which is how I need to do it). A comment on the manual page (http://www.php.net/manual/function.filemtime.php3) refers to having to use "Socket Operations" but the link posted with that comment doesn't work (it just goes to a page saying the website has been rearranged).
View Replies !
Date/time Displaying Wrong
How do I set the time display to echo the time, in the timezone the user is in and not the server time. For somereason im in eastern timezone and the host server i9s in central and the time displayed on my laptop is in central.
View Replies !
Displaying The Latest Submitted Date
I have a MySQL database with one table containing users who submit info and this is tagged to the country they're from. The query below, will list a table GROUPED according to the country and displaying the number of entries in each country. Eg: Austria - 2 Australia - 10 I am looking into the possibility of displaying the latest date from the table. For example: Two users in Australia submitted entries on 1 October and 10th October. So the "Last Date Submitted" should show, 10th October under Australia. $list_countries = mysql_query("SELECT country, date_format(date, '%M %d, %Y') AS date, count(country) AS num_of_entries FROM table GROUP BY country") Btw, each entry has its uniqueID too. How do I display the latest date when GROUPING?
View Replies !
Displaying Date - Show Dd-mm-yyyy
Having set up some info in my database. I wanted to display the date the information was posted. Entering the data into the database the date displays in the format yyyy-mm--dd. How does one go about changing this to show dd-mm-yyyy or even something like 9-sept-05?
View Replies !
Displaying 'new' Icon Based On Date?
I'd like to display a little "new" icon next to all products in a directory which are, funnily enough, new! I've got a date (timestamp) for each product which is inserted on adding a new product and updating a product. I'd like to do a conditional region using the timestamo but I'm not sure what to use - I could do === [current date] but that would only show the icon for that day and I'd like it to be there for about a week or so.
View Replies !
Reading And Displaying A Date From A MySql Database
I've just started using php, and although I am very impressed by it, there are some things with which I am confounded! What I'm trying to do is read in a Date from a mySql database and then display it on screen (the Date is in the usual yyyy-mm-dd format). If I use SQL on phpadmin SELECT Date FROM details WHERE details.Name = "Paul Lee" LIMIT 0 , 30 The result comes up 2005-01-01, so this seems to work. But if I use the following: $db = mysqli_connect("localhost","root",""); @mysqli_select_db($db, "personnel") or die ( "Unable to select database" ); $query = 'SELECT Date FROM details WHERE details.Name = "Paul Lee" LIMIT 0, 30' $result=mysqli_query($db, $query); echo "<br>"; echo $result; mysqli_close($db); I get "Object id #2" displayed on screen. I have tried to use the explode function to separate the months, year and day using the "-" as a delimeter, but this doesn't work, and I can't seem to get the other php date/time functions to work either.
View Replies !
Displaying Local Date In Specific Format
i'm trying to decide whether to use PHP or JavaScript to display a date on a website. what i'm wondering is where does PHP take the date from, the server or the client (ie will timezone become a factor). aswell as this, is there a simple way to allow the date to be displayed as: "22nd" "1st" or "14th" instead of "22" "1" or "14"?
View Replies !
Problems Displaying A Date In The Correct Format
I'm having problems displaying a date in the correct format. I'm using pear to extract a date from our back end database (the date is in DATE_FORMAT_ISO_EXTENDED), and I was to display the date in "Wednesday, February 23rd 2005, 11:04" format. Code:
View Replies !
Date Displaying And Storing In MySQL While In Wrong Timezone
I've only used php to display the current date but I can see that I'm not in the same timezone as the server is. Its 5 hours ahead and I can't get it to show the date as Eastern Time. I'm developing a site for a non-profit slopitch league so they can submit score sheets and track their season. 2 teams must submit a score sheet for their team within 72 hours of having played the game. Then they are not allowed to enter the score sheet without the administrator's permission. Code:
View Replies !
Using Strtotime()
Lets say I have a variable $time = 'Apr 30 2007 7:00AM'. Is there a function that I can use or a way of using the strtotime function to see if that variable $time is between the hours of 7am and 7pm?
View Replies !
Strtotime
I am trying to compare 2 dates, so that if a post is older that 90 days the user is not allowed to edit it. i am storing the post date in mysql in datetime field (2007-04-21 10:53:07). My question is how to user strtotime function to compare the NOW() date&time with the stored one, so if greater that 90 days return true.
View Replies !
A Bug With Strtotime
Something seems to be wrong with the strtotime function in PHP5. I've created a staff resourcing database, which is used to assign staff to projects on a weekly basis. The database stores assignments against a week ending date, which is derived using: PHP Code: $week = date('Y-m-d',strtotime('Sunday')) This works fine, $week is set to the current week ending date (Sunday) using this. However, I also create $nextweek and $lastweek using: PHP Code: $nextweek = date('Y-m-d',strtotime('next sunday',strtotime($week))); $lastweek = date('Y-m-d',strtotime('last sunday',strtotime($week))); This has also been working fine, until we got to week ending Sunday 30th October. For some reason, when $week = 2005-10-30, $nextweek becomes 2005-10-05, which is a Saturday. I've tried replacing the 'next Sunday' with '+7 days', but this returns the same date. Is this a bug? Am I missing something?
View Replies !
Strtotime &
I've got a question and was hoping someone could offer some assistance. I've got this simple line in a test file. PHP Code: echo date("Y-m-d", strtotime("next Monday")); Here's my results using different versions of PHP:PHP 4.4.7: 2007-11-04PHP 5.1.2: 2007-11-05PHP 5.2.3: 2007-11-05 Todays date is November 03, 2007 (2007-11-03).
View Replies !
Strtotime()
<?php $current = date ("F", strtotime("now")); $next = date("F", strtotime("next month")); //or try "+1 month" echo $current.'...'.$next; ?>
View Replies !
Problem With Strtotime
I am stucked with strtotime to convert date earlier than 1970 into time. Is there any other way to convert older dates between 1900-1970 into time?
View Replies !
StrToTime () Issue
I'm using strtotime to get the timestamp for midnight. I have a statistics script for my pagecounter that displays hits since midnight. I also display the number of hours and minutes passed since midnight. $start = strtotime ('today 00:00'); $timepassed = date ('H:i', time () - $start); The weird part is at 11.30 AM it says 12 hrs and 30 minutes have passed. I tried adding GMT+1 like so: $start = strtotime ('today 00:00 GMT+1'); because I suspect the fact I'm in Holland is the reason for the miscalculation. But this format is refused by strtotime. (-1) Does anyone know a) whether this is indeed the problem, and b) how to fix it. Preferrably not alone for me here, but in suc a way anyone around the globe would have a correctly working script if they'd use mine. The php page for strtotime pointed me to a link at gnu.org where the syntax for it apparantly is listed, but I get a no such page error.
View Replies !
Strtotime And Cron
I've got a db of events which have dates attached to them which have been created using strtotime(). They don't have any time.. just the date. I've got a script which gets today's date using strtotime("today"). I use this as a comparison to find events which happen today. This works fine when I call the script from a URL, however when I called the php file from a cron job... the strtotime("today") creates values which are different each time. Are there any thoughts on what could be causing this? Firstly, I was wondering if the cron job was somehow using a different timezone to me (I'm On GMT). How do I explicitly tell php to use GMT.. .but then again.. this should matter too much, because I jsut want to date not the time! It also wouldn't account for the changing values of strtotime("today"). Just out of interest, does php4 and php5 handle strtotime("today") differently? I'm just wondering if cron is using the correct version of php?
View Replies !
Strtotime Question?
I have a string that looks like (a series of them) 1 Sep 2007 21:06:11 2 Sep 2007 13:45:31 2 Sep 2007 13:45:31 3 Sep 2007 01:40:42 and I want to go strto time on it any ideas its return -1 right now so I know somethings wrong.
View Replies !
Remove 0 From Strtotime?
Like every other blog in the world, I have mine displaying the date and time of each entry. Right now this is what I'm using: echo date('h:ia', strtotime($r[date])); My latest entry's time is displayed as 07:56pm. How do I remove the 0 when the hour is a single digit?
View Replies !
Strtotime() Pre-1970
if I code $birth = strtotime(Ƈ April 1950'); then $birth = -1, I guess that this is because time "began" on 1st Jan, 1970. (although I seem to remember a few good times before that). So, what's the easiest way to find out how many days old I am (exactly, please, not just taking 1 April 1970 and adding 20 *365, which does not account for leap years?
View Replies !
Strtotime Failure
I don't know how I should input date + time into a strtotime function (i'm a total noob) so I tested this: <? $d=01; $M=01; $y=1970; $h=01; $m=01; $s=01; echo "$d $M $y $h:$m:$s"; echo strtotime("$d $M $y $h:$m:$s"); ?> I get as echo strtotime '-1', wich means the strtotime has a failure. Can anybody explain me why? Or can anybody tell me how I can make a strtotime function that puts a timestamp in the database depending on the date and time inserted in a textbox? (one textbox or one textbox to insert the day, another to insert the year,...) I should be able to change a format like (for example) this : 01-02-1990 00:00:00 (midnight) into a timestamp. so dd-mm-yyyy hh:mm:ss (or something else just to make it work)I'm clueless.
View Replies !
Strtotime With Days
On this - "next Thursday" is that next thursday or the next thursday ie: on wed will it show tomorrows time or the next week? PHP Code: <?php echo strtotime("now"); $timestamp = strtotime("now"); echo "Â Â "; $str = date('l dS of F Y h:i:s A', $timestamp); echo $str; ?> <p> <?php echo strtotime("next Thursday"), ""; $timestamp = strtotime("next Thursday"); echo "Â Â "; $str = date('l dS of F Y h:i:s A', $timestamp); echo $str;
View Replies !
Strtotime Problem
How do I find the number of seconds from a certain date to the current? I have logged in my database a completion date within the past year and I want to figure out how many seconds it has been since the completion date until now. I know the strtotime command is fairly versatile and I have tried the following without the right conclusion: PHP Code: strtotime("since ".$completion_date); //and strtotime("from ".$completion_date); What do I need to do to fix this?
View Replies !
Strtotime Busted
$thing = "2005-10-01"; $storedDate = date("z",strtotime($thing)); echo $storedDate; it just alwats returns today's date, ive tried it on a php5 server and it worked fine however on the server I need this one it is PHP4.2.
View Replies !
Strtotime - Setting From Present
I am having trouble setting the strtotime function to echo 'Y-m-d' on any day from 1 - 24 months past. I have attempted the following from links that call to different ranges of dates; 6 months, 9 months, 12 months, etc. -- from present time: My SQL is set up as follows: WHERE Date between 'pastDATE' and CURDATE() pastDATE = $HTTP_GET_VARS["getDATE"] <a href="oldies.php?getDATE=<? echo strtotime ("-6 months ago"); ?>"> 6 MONTHS OLD </a> How can I echo the strtotime as "Y-m-d"?
View Replies !
|