I have a query for showing my database :
SELECT archieve, SUM(items_in) AS income, SUM(items_out+black_out+white_out) AS outcome, SUM((ball_out+black_out+white_out
)-items_in) AS efficiency, SUM((items_in / ( ball_out + black_out + white_out))*100) AS percent
FROM items
GROUP BY archieve
ORDER BY DATE_FORMAT(archieve,'%m')
my archieve table just content month and year of data when it's submitted. For example :
Jan 2014, Feb 2014, Mar 2014
but what showed in my page is :
Feb 2014, Jan 2014, Mar 2014
This my php code to insert data from my web into database :
$date_trans = date("d M Y");
$archieve = date("M Y");
$items_in = mysql_real_escape_string($_POST['items_in']);
$ball_out = mysql_real_escape_string($_POST['ball_out']);
$black_out = mysql_real_escape_string($_POST['black_out']);
$white_out = mysql_real_escape_string($_POST['white_out']);
$ball = mysql_real_escape_string($_POST['ball']);
$black = mysql_real_escape_string($_POST['black']);
$white = mysql_real_escape_string($_POST['white']);
$note = mysql_real_escape_string($_POST['note']);
Everything's fine with the code, but how to make it ordered well by month? Because I've tried with MONTH(date) or date.(MONTH) it doesn't work. Thanks in advance ;)
You need to convert your string "archieve" to date first, and then sort by the value.
Try this:
ORDER BY STR_TO_DATE(archieve, '%M %Y')
try this
ORDER BY FIELD(archieve,'Jan','Feb','Mar',...)
or this
ORDER BY FIELD(DATE_FORMAT(archieve,'%m'),'01','02','03',...)
Related
I have a search form to search by date
in the search results page I have the follow code:
I get the POST vars
$day = mysqli_real_escape_string($database,$_POST['dd']);
$month = mysqli_real_escape_string($database,$_POST['dm']);
$year = mysqli_real_escape_string($database,$_POST['da']);
Now I echo the date with set locale
<?php
setlocale(LC_ALL,"es_ES");
echo strftime("%d de %B del %Y", strtotime('$day-$month-$year'));
?>
The result I get is
31 de diciembre del 1969
What can be wrong?
EDIT
The date is comming from HTML form like this:
dd = 30 (day)
dm = 08 (month)
da = 2015 (year)
all together gives
2015-08-30 (joining all 3 with $year-$month-$day)
I am building a booking system in php that offers session times for people to book outdoor activities.
In the summer months, there is an extra session available at the end of the day, because of Daylight Savings, there is an extra hour in the evenings.
Year Clocks go forward Clocks go back
2014 30 March 26 October
2015 29 March 25 October
2016 27 March 30 October
2017 27 March 30 October
2018 25 March 28 October
I am using this...
$todaysDate = strtotime(date("Y-m-d"));
$bstBegin = strtotime("2015-03-29");
$bstEnd = strtotime("2015-10-25");
if($todaysDate > $bstBegin && $todaysDate > $bstEnd)
{
echo "<option value="evening">Evening Session</option>";
}
I only need to show this extra option in the select list between these dates. Is this something I will need to set manually from year to year, or is there a PHP date variable that knows the days the clocks change?
$today = strtotime(date("Y-m-d"));
if (date('I', $today)) {
echo "We're in BST!";
} else {
echo "We're not in BST!";
}
or use the DateTime object equivalent, which maintains details of all the transition dates globally
I work normally with the DateTime functions and like it very much. You have a lot of possibilities to modify a date.
But in your case you can concat the actual year to your string.
$todaysDate = strtotime(date("Y-m-d"));
$bstBegin = strtotime(date('Y')."-03-29");
$bstEnd = strtotime(date('Y')."-10-25");
I hope i have understood your problem correctly.
I have found this online very good ref : https://gist.github.com/aromig/56376f76d4fb653ba83e
public function is_BST() {
$theTime = time();
$tz = new DateTimeZone('Europe/London');
$transition = $tz->getTransitions($theTime, $theTime);
$abbr = $transition[0]['abbr'];
return $abbr == 'BST' ? true : false; }
I have problem with my php/mysql.
I want to get distinct year from my fields ex 2013-06-20.
Now I get something like this :
2014
2013
2014
2013
2013
2014
2014
2014
2014
2014
2014
2014
PHP CODE :
<?$chuj=mysql_query("SELECT DISTINCT date_issue FROM invoices_sales ");
while($chuje=mysql_fetch_object($chuj)){
$test=explode("-",$chuje->date_issue);
print_r($test['0']."<br>");
}
?>
How I can get only once 2013 or 2014 year ?
You need to grab the year from that particular date string.
SELECT DISTINCT YEAR(date_issue) FROM invoices_sales
This will ensure it's only comparing the year, as it stands, each of those strings likely have different dates, so it is evaluating the entire date as opposed to only the year.
<?php
$chuj=mysql_query("SELECT DISTINCT YEAR(`date_issue`) as `yr` FROM `invoices_sales`");
while($chuje=mysql_fetch_object($chuj)) {
$test = $chuje->yr;
print_r($test['0'] . "<br>");
}
?>
I have tried a new thing . I am not sure if its correct or not but unfortunately its not working but also not giving any problem. :( :)
I am trying to remove some specific text from the title before it get insert into DB. So here is my code
$rows = array();
$hdate=date("l, Fj, Y");
foreach($obj->rss->channel->item as $item)
{
$rows[] = "('".mysql_real_escape_string(str_replace("Horoscope for $hdate ", '', "$item->title"))."','".mysql_real_escape_string($item->description)."')";
}
I am trying to remove String "Horoscope for Friday, April 26, 2013" from each row. The title looks like "Aries Horoscope for Friday, April 26, 2013" . Since the day also updates everyday so I have declared the hDate format . Here is my DB inserted looks like
http://i.imgur.com/12BkisD.png?1
The above works perfectly but still after running the code it dont delete the string form the title.
Thanks in advance.
//Aries Horoscope for Friday, April 26, 2013
echo $hdate=date("l, Fj, Y");
//Thursday, April25, 2013
echo $hdate=date("l, F j, Y"); //use this
//Thursday, April 25, 2013
may be this help
preg_replace('{Horoscope for.*}','',$title);
I have a question that is making me crazy,
My Task is to parse a date from an API and transform it to RFC 822 format, because the feed that is coming out gets an validation error
the date from the API looks like this :
<review created="2012-10-23 14:51:12.0">
I have one Date in the description made via substr
$xtime = substr($review["created"], 0, 16);
$jahr = substr($xtime,0,4);
$mon = substr($xtime,5,2);
$tag = substr($xtime,8,2);
$datneu = $tag.'.'.$mon.'.'.$jahr;
this date will be rendered like :
23.10.2012
For the pubdate I made
$xtime = substr($review["created"], 0, 16);
$xxl = $pubtime . " GMT";
rendered like :
2012-10-23 14:51:12 GMT
And W3C feed validator says it´s not validate because pubDate is not in RFC 822 form
Sorry
This feed does not validate.
line 10, column 38: pubDate must be an RFC-822 date-time: 2012-10-29 11:51:23 GMT (5 occurrences) [help]
<pubDate>2012-10-29 11:51:23 GMT</pubDate>
and it needs to look like :
<pubDate>Wed, 02 Oct 2002 13:00:00 GMT</pubDate>
i can imagine a hacky solution for expressing sth like "if (month = 01){ actualmonth = Jan}" but i really don´t know how to do same with the days,
Also i´m not too comfortable with PHP but I need to solve this asap.
Hope you can help me, there must be a solution i didnt found at similiar questions
regards John
Have a look at DateTime::createFromFormat() or date_create_from_format.
http://fr2.php.net/manual/en/datetime.createfromformat.php
<?php
$date = date_create_from_format('Y-m-d H:i:s', '2012-10-23 14:51:12.0');
echo date_format($date, 'D, d M Y H:i:s');
?>
Have a look at the possible date formats
http://fr2.php.net/manual/en/function.date.php
EDIT: fixed
Hi in PHP you should look at this: function date
yeaaaaah that worked for me, amazing!
for others the exact solution for my Case was
$before = "2012-10-23 14:51:12.0";
$timetwo = substr($before, 0, 16);
$timethree = date_create_from_format('Y-m-d H:i:s', $timetwo);
$timefinal = date_format(timethree, 'D, d M Y H:i:s');
$after = $timefinal . ' GMT' ;
$after = "Mon, 23 Oct 2012 14:51:12 GMT";
thanks a lot for the quick answers you are awesome!
This worked for me....
date("r", strtotime($yourdate))
$yourdate was 2013-10-27 and I got Sun, 27 Oct 2013 00:00:00 +0000