I am trying to compare the months of two dates using the jquery datepicker. I want it to check and see if my end date has the same month as my start date so that I can add in the end date month if needed:
Instead of displaying:
Event Dates
January 1st - 1st, 2017
March 3rd - 4th, 2017
I want to display:
Event Dates
January 1st - February 1st, 2017
March 3rd - 4th, 2017
This is the code I have so far. PS. I am using advanced custom fields within wordpress. That is why get_field('event_start_date') pulls in the date. The only argument I really need help with is the <?php if ($endDate[M] != $startDate[M]): ?> code. That was just my best guess on how to do this but it does not work at all.
<p>
<?php if( get_field('event_start_date') ): ?>
<?php $startDate = DateTime::createFromFormat('Ymd', get_field('event_start_date')); ?>
<?php echo $startDate->format('F'); ?> <?php echo $startDate->format('jS'); ?>
<?php if( get_field('event_end_date') ): ?>
<?php $endDate = DateTime::createFromFormat('Ymd', get_field('event_end_date')); ?>
-
<?php if ($endDate[M] != $startDate[M]): ?>
<?php echo $endDate->format('F'); ?>
<?php endif; ?>
<?php echo $endDate->format('jS'); ?>, <?php echo $endDate->format('Y'); ?>
<?php else : ?>
, <?php echo $startDate->format('Y'); ?></span>
<?php endif; ?>
<?php endif; ?>
</p>
Related
I am using a page to display order details and want to show invoice no and date in that page. Please tell me how to show invoice no. Here is the code:
<div class="col-sm-4 invoice-`co`l">
<b>Order No. </b>#
<?php if ($this->getNoUseOrderLink()): ?>
<?php echo $_order->getRealOrderId(); ?>
<?php else: ?>
<?php echo $_order->getRealOrderId(); ?>
<?php endif; ?>
<br>
<b>Amount:</b> <?php echo " ".$this->gettotalamount(); ?><br>
<b>Payment Type:</b> <?php echo $_order->getPayment()->getMethodInstance()->getTitle(); ?>
Below is the code snippet to get Invoice info associated with any order. Based on your code, you have already loaded order model on $_order, so try below code.
<?php
// ignore below two lines if you already have order model
// $_order=Mage::getModel('sales/order')->loadByIncrementId($anyorderincrementid);
// $_order=Mage::getModel('sales/order')->load($anyorderentityid);
if ($_order->hasInvoices()) {
$invIncrementIDs = array();
foreach ($_order->getInvoiceCollection() as $inv) {
echo "Invoice Id- ".$inv->getIncrementId();
echo "Invoice Date- ".date('d-m-Y',strtotime($inv->getCreatedAt()));
}
}
?>
To get date in d-m-y format (answer of your question which is in comments)
<?php
// format admin and store date
$orderAdminDate=date('d-m-y',strtotime($orderAdminDate));
$orderStoreDate=date('d-m-y',strtotime($orderStoreDate));
echo $orderAdminDate;
if ($orderAdminDate != $orderStoreDate):
echo date('d-m-y',strtotime($_order->getCreatedAtStoreDate()));
echo $orderStoreDate;
endif;
?>
my wordpress theme i created shows just the first timestamp of the first article of multiple article on the page. On the rest of them there is just a empty space, so php generated no echo.
I think that there is something wrong with the loop, but i found similar loops on the wp page. Can someone help me ?
here is my code
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="entry">
<h2 class="title"><?php the_title(); ?></h2>
<div class="time-text">added on: <?php the_date('d.m.Y'); ?> - Author: <?php the_author(); ?></div>
<div id="text_post" style="margin-top:20px;">
<?php the_content(); ?>
</div></div>
<?php endwhile;endif?>
It's how the the_date function works. Quoting the "special note" on that page:
SPECIAL NOTE: When there are multiple posts on a page published under
the SAME DAY, the_date() only displays the date for the first post
(that is, the first instance of the_date()). To repeat the date for
posts published under the same day, you should use the Template Tag
the_time() or get_the_date() (since 3.0) with a date-specific format
string.
Try using <?php echo get_the_date('d.m.Y'); ?> instead of <?php the_date('d.m.Y'); ?>. That's untested - I'm just going by that quote.
First you need to open these three files:
index.php
single.php
page.php
Then you will need to locate the following code:
<?php the_modified_time('F jS, Y');?>
Note: Since there are so many formats of displaying dates, you might not see the exact code, but something along this line.
Replace it with:
<?php $u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
echo "and last modified on ";
the_modified_time('F jS, Y');
echo " at ";
the_modified_time();
echo ", "; } ?>
I generated a tabs of months with anchor tag and href is equal to query string of ?m=1&y=2014. The year part will be incremented accordingly with next and previous button. By the way this is in a wordpress environment.
--Code--
Next and previous button for year.
<div class="table-header">
<div class="table-header-wrapper">
<div class="prev"></div>
<div class="year"><?php echo $current_year; ?></div>
<div class="next"></div>
</div>
</div>
--Code--
Tab months
<?php
for ( $monthNum = 1; $monthNum <= 12; $monthNum++ ) :
$month = date( 'M', mktime( 0,0,0, $monthNum, 1, $current_year ) ); // month in 3 letter format e.g. Jan
$current_monthNum = date( 'n' ); // current month in number
?>
<div class="<?php echo strtolower( $month ); ?> month" data-month="<?php echo $monthNum; ?>">
<?php echo $month; ?>
</div>
<?php
endfor;
?>
With PHP its not possible as PHP is a server side scripting language.
You can achieve it with jQuery.
Hashchange plugin serves your need.
Here, you can change hash of url on some event.
And fire some event on haschange.
You can change your hashes on Previous and Next buttons.
I have this code.That is showing 5 business days(that is correct). but i want only current weekdays even that is passed. after passing of current week next weekdays shows
<?php for($i=0;$i<=4;$i++): ?>
<label ><?php echo date('d-M-Y', strtotime("+$i Weekday")); ?></label>
<label ><?php echo date('l',strtotime("+$i Weekday")); ?></label><br>
<?php endfor; ?>
Its output is:
19-Nov-2014 Wednesday
20-Nov-2014 Thursday
21-Nov-2014 Friday
24-Nov-2014 Monday
25-Nov-2014 Tuesday
This is also showing next week days.
what i want is like this:
17-Nov-2014 Monday
18-Nov-2014 Tuesday
19-Nov-2014 Wednesday
20-Nov-2014 Thursday
21-Nov-2014 Friday
Try this:
$monday_this_week = date("Y-m-d",strtotime('monday this week'));
<?php for($i=0;$i<=4;$i++): ?>
<?php $date = date('d-M-Y', strtotime("+$i days", strtotime($monday_this_week))); ?>
<label ><?php echo $date; ?></label>
<label ><?php echo date('l', strtotime($date)); ?></label><br>
<?php endfor; ?>
Hello I currently have this PHP Script
<?php if($purchase_dates != FALSE){?>
<?php foreach($purchase_dates as $id=>$outer_value) { ?>
<!-- Output the date here -->
<!-- Start Purchase table -->
<?
$date = strtotime($outer_value['date_purchased']);
$data = date('F jS Y', $date);
?>
<h3></h3>
<!-- Start inner loop -->
<?php foreach($purchases as $id=>$inner_value) { ?>
<?php if($inner_value['date_purchased'] == $outer_value['date_purchased']) { ?>
<div class="row">
<ul>
<li class="id"><?=$inner_value['code'];?></li>
<li class="name"><?=$inner_value['firstname'];?> <?=$inner_value['surname'];?></li>
<li class="download">Download PDF</li>
<div class="disp">
<li class="location"><?=$inner_value['city'];?></li>
<li class="status"><?=$job_status[$inner_value['job_status']];?></li>
<li class="education"><?=$education_types[$inner_value['education_level']]['nice_name'];?></li>
<li class="role">
<?php
$out = array();
if($inner_value['is_contract'] == 'Y') $out[]="Contract";
if($inner_value['is_permanent'] == 'Y') $out[]="Permanent";
if($inner_value['is_temporary'] == 'Y') $out[]="Temporary";
echo implode(", ",$out);
?>
</li>
<li class="salary"><?=$salaries[$inner_value['expected_salary_level']]['nice_name'];?></li>
</div>
</ul>
</div>
<?php } ?>
<?php } ?>
<!-- End inner loop -->
<?php } ?>
<?php }?>
<!-- End Outer Tree Loop -->
This generates something that looks like this,
22nd July
Purchase1
22nd July
Purchase 2
18th July
Purchase 3
18th July
Purchase 4
My question is, I want to group all the purchases that are on the same under that date and also if that date is todays date I want to replace '23rd July' with 'Todays Purchases'
I am already using groupby in my SQL
The easiest way to group by a date is to add an extra dimension to your arrays, so all entries that belong to the same date are in the same subarray. Then you just need to loop twice:
foreach($data as $purchase_date => $purchases){
// Print date
foreach($purchases as $id=>$inner_value){
// Print purchase
}
}
You appear to be using Unix timestamps for dates, so you can simply use date() to strip hours, minutes and seconds:
if( date('Y-m-d')==date('Y-m-d', $purcharse_date) ){
// Today
}