last day (15 days later) » 

15:30
0
A: Custom date range format on a node by node basis

Shabir A.You just need to add template_preprocess_node(&$vars) to your template.php and check the value of checkbox that is controlling the date format Date object store start date as value key and end date as value2 key. You need to check on that. if($checkbox) //checked //display one format else ...

Thanks for your suggestion, the date formatting part is the tricky one because of the way the dates are stored within the node object. Can you add an example of how to display the format(s) above?
edited my question: you need to check against both the value and format your date accordingly. like. $field_date['und'][0]['db']['value']->dateOnly = true // start date similarly for end date
I had no idea dateOnly can be used like that, so setting it to TRUE would just display the date part excluding the time, no matter the format selected under Display settings? I'll give that a try.
In my case, dpm ing $vars only returns value, value2, timezone, timezone_db and date_type. All these are stored in the field's array, under $vars->field_node_date[0]. Any ideas on how to access dateOnly?
better to load node with node_load($nid)
I get the exact same thing within $node.
15:30
I am not sure which version of date api are you using, but alternative route is to check against value and value2 and do all the format stuff on your values.
I'm using 7.x-2.8, do you think 7.x - 2.9 provides all these attributes? I'll see if it does. In the meantime, value & value2 values never change, no matter the display settings as they correspond the values stored in the dabase (e.g. 2014-04-30 22:30:25). As a result, I'm not sure how I can alter these, which is the base of my problem.
Why are you altering these values, just format your custom format from these values
for some nodes (where a checkbox is checked), I need to present the field's output without the time, that's all.
in date.theme, the theme functions construct the output, e.g. for date range, for single date and so on. This is a different thing than changing the date format e.g. "long", "short" etc.
in node preprocess do something like this

$start = ..value;
$end = ..value2 // both are in YYYY:MM:DD HH:MM:SS format

Check the checkbox value if its one apply the format

$date_format = date()

if (!empty($value2)) // in case end date not empty

$date_string = date();
I need to keep the selected format (which is currently set to "long" on display settings for the default view mode) and just alter the output by presenting just the date, not the time.
15:36
can you tell me what is the problem of the algorithm I just sent you
ok so first you get the start and end dates set in the db, that's OK.
what's with the $date_format = date() ?
the format you want to render
date only
ok so you assign the desired format to $date_format.
How do you actually apply that to the stored dates?
15:40
$today = date("F j, Y");
plain php
or with date_format
on the array you're dumping on my question page, to which value do you assign the date / date_format?
I mean, within the node object, which value do you set as the format?
By the way, updating the module to latest version doesn't add anything to my dpm
start date and end date are the values need to be formatted right?
give me screenshot of your date field
that's what I have in my field, dpm straight from preprocess_node
and inside $vars['content'], that's what the field contains:
So as you can see, value & value2 are what's stored in the db, nothing to do with format.
I can do whatever I want with value & value2 but I don't know how to override the output on my node basically...
give me some time please!
15:50
I am still not sure what's the problem with changing the format with php date() function
Given the screenshots I showed you, can you give me a real code example of what you mean?
Sorry but this pseudo code can be confusing, especially after trying to solve that for the last few hours!
In the meantime...
this:
changes the value but not the way the date is rendered. My output is exactly the same as before, not sure if that's what you meant.
what?
Yes, I can change the values, ie value & value2 as I like and I can see the change in my dpm. But when the date is rendered (for example on a node page, the template generates the page with that: <?php print render($content['field_event_date']); ?>) and I get the same exact thing.
So when $content['field_event_date'] goes through render, what's important is the format of the date selected on UI display settings (e.g. "long"), not the value of the date.
I hope everything is more clear now...?
16:05
if($var['field_checkbox_name']['und'][0]['value'] == 1) //make sure the correct value
{
$start_date = $var['field_event_date'][0]['value'];
$var['new_formated_date'] = date("F j, Y", strtotime($start_date));
if(!empty($var['field_event_date'][0]['value2'])) {
$end_date = $var['field_event_date'][0]['value2'];
$var['new_formated_date'] .= 'to '. date("F j, Y", strtotime($end_date));
}
}
}
something like this
based on first screenshot
do you have node.tpl.php for your event node?
Oh, and then print $new_formated_date in my template? That's what you mean?
if (!empty($new_formated_date)) then print $new_formated_date
otherwise default date
well as I mention in my initial question, ...Programmatically altering the markup of the field would probably not be a preferred solution as any change of the format on the UI under display settings (e.g. from long to short etc) would be ignored....
yes.. then in that case you need a way to get the format which has been used and use the same format
I'm working with very specific wordings in the template and the HTML has to be specific and following the date.theme's functions. So I would have to replicate everything according to that, e.g. <span class="date-display-start">Tuesday 03 May 2016 - 17:02</span>
But that I need to avoid
Yes, that's my problem :) Any thoughts on that?
Also, the solution above is not going to work on all view modes and all templates, I would have to copy it across my whole codebase, wherever event nodes are rendered.
And that's not possible, it's too messy.
16:13
yes, it was just a workaround
which could work for simple cases..
thanks for your time on that Shabir, I appreciate.

last day (15 days later) »