PHP - Turning Date Fields Into Actual Dates
I have got a date field in my mysql database with events, and as you know date in MYSQL uses yyyy/mm/dd but I would first like to turn this around to dd/mm/yyyy but also turn this into for example "Tuesday - May 1990" would anyone like to point me into the right direction?
Much appreciated! Similar Tutorialsi have a table that shows payments made but want to the payments only showing from a set date(06/12/14) and before this date i dont want to show
this is my sql that doesnt seem to work and is showing dates before the specified date.
.
"SELECT * FROM payments2014, signup2014, editprop2014 WHERE signup2014.userid = payments2014.payment_userid AND editprop2014.prop_id = signup2014.prop_id AND signup2014.userid !='page1' AND signup2014.userid !='page6' AND signup2014.userid !='page4' AND payments2014.payment_transaction_status !='none' AND payments2014.payment_transaction_status !='CANCELLEDa' AND payments2014.payment_type !='deposit' AND payments2014.payment_paid_timestamp NOT LIKE '%2012%' AND payments2014.payment_paid_timestamp NOT LIKE '%2011%' AND payments2014.payment_paid_timestamp >= '06/12/14' ORDER BY payments2014.payment_id DESC"i have some other parts in the statment but this one that should be filtering is host_payments2014.payment_paid_timestamp >= '06/12/14'thanks in advance Hi... Good day! I have table that has a field from_date and to_date. Now I just want to know if how can I display as table format the dates between from_date to_date. Like this from_date: 2011-12-16 to_date: 2011-12-31 I want to display it: 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 // table format. Thank you I'm trying to wrap my head around how i should go about doing this. I have two dates...2011-05-03 and 2011-05-08. I want to write a function that creates an array of the days that consist of that date range. So say something like Code: [Select] <?php $start = "2011-05-03"; $end = "2011-05-08"; function get_days($start, $end) { //code to get the days } echo get_days($start, $end); //hopefully produce something like... $day['1'] = "2011-05-03"; $day['2'] = "2011-05-04"; $day['3'] = "2011-05-05"; $day['4'] = "2011-05-06"; $day['5'] = "2011-05-07"; $day['6'] = "2011-05-08"; anybody know any idea how to do something like this? Pretty sure i'm going to need the mktime() function to account for ranges going across months and years. I have two text fields in a form. Both accepts dates. I'd like to check whether the second date provided is exactly one year in the future from the first provided date.
I can easily do this in PHP but since I need to do the check once the user leaves the second field, I have to resort to JavaScript, using onblur or something.
There are two issues I have.
1. Make sure that the strings provided are indeed dates (I would use strtodate() in PHP for this)
2. Regardless of month provided, making sure that the second date is exactly a year in the future of the already provided year
I've only captured the values and passed them to Date(). However, it can only handle european style, and if I enter 1981-06-16, the value returned is Jun 15 1981 17:00:00 which is obviously wrong.
Here is the simple broken code I have
var text1 = document.getElementById("text1"); var start_date = new Date(text1.value); var text2 = document.getElementById("text2"); var end_date = new Date(text2.value); alert(start_date);I need some guidance. I'm trying to do the following PHP. I have written it in English if (today's date) => date1 AND <= date2 then {display image1} elseif (today's date) => date3 AND <= date4 then {display image2} else {display image 13} There are 24 fixed dates and 13 fixed images. I have tried using combinations of strtotime(), replacing the date value with variables, hard coding the dates within the program. I don't seem to be able to get any combination to work properly. I'm sure it's just a syntax error but I can't see it. When I've searched the web all the answers I've found relate to dates within databases but as I only have 24 dates it seems a bit of overkill. I would appreciate any pointers to the correct method I might be able to use. The dates need only a day and month as I would like this to repeat year after year. <?php $today = strtotime(date('d-m')); if (strtotime($today) >= strtotime('28-10') && strtotime($today) <= strtotime('24-11')) {echo "<div>image1</div>";} elseif (strtotime($today) >= strtotime('25-11') && strtotime($today) <= strtotime('22-12')) {echo "<div>image2</div>" ;} elseif (strtotime($today) >= strtotime('23-12') && strtotime($today) <= strtotime('24-02')) {echo "<div>image3</div>" ;} else {echo "<div>image13</div>";} ?> The result I get from this is image1 appears on the web page but I would expect image3 as today is 22-01 Thank you in advance. Andrew I have date stored in database in any of the given forms 2020-06-01, 2020-05-01 or 2019-04-01 I want to compare the old date with current date 2020-06-14 And the result should be in days. Any help please? PS: I want to do it on php side. but if its possible to do on database side (I am using myslq) please share both ways🙂 Edited June 14, 2020 by 684425I have a query that fetches all the dates in a date range then displays them in a Date:HH:MM;SS format. However when displayed sometimes there are missing Hours as I don't have data for them and I would like to display it. So right now I have something like this. Date Column: Revenue_Column: 07/29/2010 00:00:00 $250.00 07/29/2010 01:00:00 $150.00 07/29/2010 03:00:00 $350.00 07/29/2010 04:00:00 $450.00 As you can see 02:00:00 is missing, how can I use php or possibly mysql to fill in that gap? I have tried creating an hours table and joining them and grouping by date however that doesn't seem to work. Any ideas? I would like to know the best practice to achieve the following: I have a list of dates related to live events for performing artists. When someone views the web page that contains a section to display the dates, I would only want to show the dates from today into the future and not show any dates from the past. What is the best way to accomplish this? Thanks in advance... I have a calendar select date function for my form that returns the date in the calendar format for USA: 02/16/2012. I need to have this appear as is for the form and in the db for the 'record_date' column, but I need to format this date in mysql DATE format (2012-02-16) and submit it at the same time with another column name 'new_date' in the database in a hidden input field. Is there a way to do this possibly with a temporary table or something? Any ideas would be welcome. Doug Hi guys I hav a form where a user selects an end time and the date will be 4 days from today. I have been able to get the date to populate, but I am trying to join the two fields together but with no luck. I have the end date caluclated using the code below and this works Code: [Select] $end_date=date("Y-m-d",$dateplus4); The end time is selected from a menu where the user selects either 12 or 17 (12:00:00 or 17:00:00) I have tried Code: [Select] $end_date_time=$end_date." ".$end_time; I have also tried strtotime and mktime, but obviuosly not doing it properly. Any help would be great. My query is a fixtures list for my local sports team- There seems little point including fixtures from the past as they are in a results query anyway. I'm ordering by date (see below) but how can I remove the ones already past? $query = "SELECT * FROM fix10 ORDER BY Date"; TIA Nick Hi All, I need to subtract dates and display the number of days left. I have a 'Start' date and an 'End' date in DATETIME format in the DB. Not quite sure where to start. A simply start - end doesn't work . Start = 2011-11-01-00:00:00 End = 2011-11-30-23:59:59 Since it is now 2011-11-27, my output should equal 3. Any help is appreciated. Hi guys, I am trying to do a multidates events availability calender. The script below indicates todays date by highlighting an orange colour and also indicates the start and end date of the event highlighting grey colour on the two dates (The colour are link via css classes as shown). Code: [Select] //Today's date $todaysDate = date("d/m/Y"); $dateToCompare = $daystring . '/' . $monthstring . '/' . $year; echo "<td align='center' "; if($todaysDate == $dateToCompare){ echo "class='today'"; }else{ //Compare's the event dates $sqlcount = "select event_start,event_end from b_calender where event_start ='".$dateToCompare."' AND event_end='".$dateToCompare."'"; $noOfEvent = mysql_num_rows(mysql_query($sqlcount)); if($noOfEvent >= 1){ echo "class='event'"; } } It works ok i.e. if start date = 01/01/2012 and end date = 04/01/2012 both date will be highlighted with grey colour. However I want it to also highlight grey on the dates between the 1st and 4th to show that then anydates between the 1st and 4th are not available and this is when I'm stuck. Please guys I need help. Thanks Good day all
My site is hosted on yahoo server. Due to security reason, .htaccess is not allowed. I need to hide (or mask) actual url, or atleast .php file name. Can anyone help.
Warm regards.
Shonali
Say I have a string (stored in a variable we'll call $mystring) that could be something like this... "cat / dog / monkey / / / / / / / /" Or this string could also have no real data in it, in which case it would look like... "/ / / / / / / / / /" QUESTION: What is the easiest/most efficient way to run a check on that string to see if there are any non-slash characters in it. In plain english, the check would say, "Are there any letters in this string, or is it only spaces and slashes?" Any ideas? Hi, I have a file which contains settings for a user. Similar to wordpress except simpler like setting a default email for error messages or something. The idea is that it's used as an installation script for web-ware where someone fills in a form with their database details, my script will hard-code them into the settings file and then delete itself. I'll admit I did get the idea from wordpress. Only the way it's coded currently requires a certain combination of characters at the end and seems really messy. The script looks like this (and does work): $endpos = strpos ( $contents, '"; //replace with name//', $startpos); The settings file looks like this: $hard_name = "Smith"; //replace with name// As you can see I use the comment in the settings file, which follows what I'm actually changing, to find the end of the variable. I am sure there must be a better way of doing things but don't know what. It just seems really inefficient because if the comment is removed the script breaks. Any info and tips would be much appreciated. IceKat Can you see if a request (post/get) is from a curl request or an actual user? I am trying to defeat a little bit of fraud. Hello, Sorry for my english... Well, I make a smaill website. members has to login and then member can see pictures (saved in a folder). When the admin upload pictures a folder wil be created. To get the actual folders in the "album" folder I use this code. <?php //get the folders $handle = opendir(realpath('../album/Album/.')); while ($direc = readdir($handle)) { if($direc == '.' || $direc == '..') continue; else { echo "\t\t<input type='checkbox' name='map[]' id='map[]' value='" . $direc. "' />" . $direc . "<br />\n"; } } closedir($handle); ?> The admin has to assign the folders wich are allowed to see by a member. I use checkboxes for that. And now my problem: When a member can see folder 1 to 4 and the admin upload 2 new folders and want to give that member to see these 2 new folders I want the following: 6 checkboxes (checkbox 1 > album 1, checkbox 2 > album 2... etc). As is said, this member can see folder 1 to 4, so in the CMS album 1 to 4 has to be checked ans album 5 to 6 not. This is my code for that: <?php $sql2 = "SELECT url FROM url WHERE gebruiker_id =" . $_GET['id'] . " ORDER BY url ASC"; $res2 = mysql_query($sql2); while ($rij = mysql_fetch_array($res2)) { $url = $rij['url']; // mappen ophalen $handle = opendir(realpath('../album/Album/.')); while ($direc = readdir($handle)) { if($direc == '.' || $direc == '..' || $direc == $url) { continue; } echo "\t\t<input type='checkbox' name='map[]' id='map[]' value='" . $direc. "' />" . $direc . "<br />\n"; } closedir($handle); } ?> Now my output is: <input type='checkbox' name='map[]' id='map[]' value='album 2' />album 2<br /> <input type='checkbox' name='map[]' id='map[]' value='album 3' />album 3<br /> <input type='checkbox' name='map[]' id='map[]' value='album 4' />album 4<br /> <input type='checkbox' name='map[]' id='map[]' value='album 5' />album 5<br /> <input type='checkbox' name='map[]' id='map[]' value='album 6' />album 6<br /> <input type='checkbox' name='map[]' id='map[]' value='album 1' />album 1<br /> <input type='checkbox' name='map[]' id='map[]' value='album 2' />album 2<br /> <input type='checkbox' name='map[]' id='map[]' value='album 4' />album 4<br /> <input type='checkbox' name='map[]' id='map[]' value='album 5' />album 5<br /> <input type='checkbox' name='map[]' id='map[]' value='album 6' />album 6<br /> <input type='checkbox' name='map[]' id='map[]' value='album 1' />album 1<br /> <input type='checkbox' name='map[]' id='map[]' value='album 2' />album 2<br /> <input type='checkbox' name='map[]' id='map[]' value='album 3' />album 3<br /> <input type='checkbox' name='map[]' id='map[]' value='album 5' />album 5<br /> <input type='checkbox' name='map[]' id='map[]' value='album 6' />album 6<br /> What do I have to do to check the checkboxes (album 1-4) and not to check the album 5-6??? My guess it has to do with the While in While loop but... Greetings, Ferdi I was hoping someone could help me figure out why my Code: [Select] header('Location: .');works right on my localhost testing computer but not when I load it onto the actual server. Here are the two files in question. The first is a snippet from my index.php controller file. Code: [Select] if (isset($_POST['action']) and $_POST['action'] == 'Edit') { include '../../includes/db.inc.php'; { $id = mysqli_real_escape_string($link, $_POST['id']); $sql = "Select * from s_times where id = '$id'"; $result = mysqli_query($link, $sql); if (!$result) { $error = 'Error fetching service time details ' . mysqli_error($link); include '../../includes/error.php'; exit(); } $row = mysqli_fetch_array($result); $pagetitle = 'Edit Category'; $action = 'editform'; $id = $row['id']; $day = $row['day']; $time = $row['time']; $event = $row['event']; $avail = $row['avail']; $orderby = $row['orderby']; $button = 'Update'; } include 'stimes_modify.php'; exit(); } if (isset($_GET['editform'])) { include '../../includes/db.inc.php'; $id = mysqli_real_escape_string($link, $_POST['id']); $day = mysqli_real_escape_string($link, $_POST['day']); $time = mysqli_real_escape_string($link, $_POST['time']); $event = mysqli_real_escape_string($link, $_POST['event']); $avail = mysqli_real_escape_string($link, $_POST['available']); $orderby = mysqli_real_escape_string($link, $_POST['orderby']); $sql = "Update s_times set day = '$day', time = '$time', event = '$event', avail = '$avail', orderby = '$orderby' where id = '$id'"; if (!mysqli_query($link, $sql)) { $error = 'Error updating service times ' . mysqli_error($link); include '../../includes/error.php'; exit(); } header('Location: .'); exit(); } here is the stimes_modify.php file code Code: [Select] if (isset($_POST['action']) and $_POST['action'] == 'Edit') { include '../../includes/db.inc.php'; { $id = mysqli_real_escape_string($link, $_POST['id']); $sql = "Select * from s_times where id = '$id'"; $result = mysqli_query($link, $sql); if (!$result) { $error = 'Error fetching service time details ' . mysqli_error($link); include '../../includes/error.php'; exit(); } $row = mysqli_fetch_array($result); $pagetitle = 'Edit Category'; $action = 'editform'; $id = $row['id']; $day = $row['day']; $time = $row['time']; $event = $row['event']; $avail = $row['avail']; $orderby = $row['orderby']; $button = 'Update'; } include 'stimes_modify.php'; exit(); } if (isset($_GET['editform'])) { include '../../includes/db.inc.php'; $id = mysqli_real_escape_string($link, $_POST['id']); $day = mysqli_real_escape_string($link, $_POST['day']); $time = mysqli_real_escape_string($link, $_POST['time']); $event = mysqli_real_escape_string($link, $_POST['event']); $avail = mysqli_real_escape_string($link, $_POST['available']); $orderby = mysqli_real_escape_string($link, $_POST['orderby']); $sql = "Update s_times set day = '$day', time = '$time', event = '$event', avail = '$avail', orderby = '$orderby' where id = '$id'"; if (!mysqli_query($link, $sql)) { $error = 'Error updating service times ' . mysqli_error($link); include '../../includes/error.php'; exit(); } header('Location: .'); exit(); } The functionality of both pages seems to be working in relation to editing the database but the page will not redirect back to the main page when it gets back down to the header line. Like I said it works on localhost just not on actual server. I also tried putting in the full URL like this Code: [Select] header('Location: http://www.bbcpa.org/dbsite/admin/stimes/stimes/php');and still got a blank page. The URL in the address bar shows this http://www.bbcpa.org/dbsite/admin/stimes/?editform it should show this http://www.bbcpa.org/dbsite/admin/stimes/ so maybe something is wrong with this line in stimes_modify.php Code: [Select] <form action="?<?php htmlout($action); ?>" method="POST"> anyway any help would be greatly appreciated. Thanks having a problem turning this sql into a query and I need it to only update rows where id field is empty. Code: [Select] UPDATE systems SET naqahdah = naqahdah + naqahdah_mines * 2 I tried this out with failure Code: [Select] <?php mysql_query("UPDATE systems SET naqahdah= naqahdah + naqahdah_mines * 2 WHERE id <> ' ' "); ?> so i tried getting rid of WHERE and couldnt even get this to work. I tested the sql out it works fine. Code: [Select] <?php mysql_query("UPDATE systems SET naqahdah= naqahdah + naqahdah_mines * 2 "); ?> |