Add a class depending on date - date

I have a standard link that I would like to add a class to depending on a date. Is this possible using Javascript/JQuery?? My code at the moment is simply this:
<div id="box1">1</div>
So if the date is actually 1st July I would like the class to change to "current" and if the date is past 1st July (2nd, 3rd, 4th etc) then the class to be "active".
I'm thinking there maybe a way to do this via Javascript or JQuery or possibly PHP. I'm not a developer so really not too sure. Any help would be appreciated. Thank you in advanced.

Something like this:
Do your date logic
Remove the class: $("#box1 a").removeClass('disabled');
Then add class: $("#box1 a").addClass('active');

Related

eonasdan datetimepicker century threshold

Any tips would be welcome: I need the datetimepicker to transform a date earlier than 1969 to that year in the 20th century. So if I enter 12-12-69 the datetimepicker transforms that into 12-12-1969. Entering 12-12-68 though is transformed into 12-12-2068. I assume this is done in moment.js, but I may be mistaken. If it is done in moment.js anyone have an idea where to look to change the threshhold for this automagic transformation? I'd rather change it in the library than use parseInputDate, but if anyone has an example on usage of parseInputDate, please share. I have found that the date already has been changed automagically as ddescribed above when I try and access the date-object via:
$('#datefrom').on('dp.change',function(e) { console.log(e.date); });
I need to access the date object B4 this happens. It works to set a onchange="dostuff()" inline on the input field itself, but that sort of feels wrong, as I want to handle this in one place in the datetimepicker and not in 50 places inline.

reformat date that is pulled from database table

I have a website which uses smarty templates.
I have a table in my db called posts that has various columns, one being "date_added". I managed to have that displayed on the posts by editing one of the Smarty templates for "posts" however, the date format is YYYY-MM-DD.
Is there any easy way for me to change this? Perhaps with jQuery?
Ideally, I want to only show the abbreviated month, with the day positioned next it. This is for a blog style post, but this isn't WordPress.
Right now the smartytemplate the shows the date_added reads like this:
{$posts[i].date_added|stripslashes|nl2br}
Where posts is the table and date_added is a column in that table.
An exact example can be seen here in the top right corner of each post.
http://www.elegantthemes.com/preview/LightBright/
Does anyone have a good suggestion of how I can achieve the desired request?
If you are looking for a javascript solution, you can take a look at the incredible JS Library MomentJS. It is very lightweight and does numerous date and time formats.
http://momentjs.com/
Just include the minified script file in your HTML .
For your exact case, you would use momentJS as such:
First create the momentJS date object:
var moment_date = moment(date_from_database, "YYYY-MM-DD");
Then to display the date as you want:
var date_string = moment_date.format("MMM DD"); // ex. = "Mar 03"
More documentation here: http://momentjs.com/docs/#/displaying/
Then you can use your DOM manipulation library (JQuery for example) to place that string somewhere in your HTML
Good luck
- K

JQuery Mobile/Datebox, difference between display date format and submit date format

Is there a way to display a date in an input different from the format I want to submit.
For example I have to submit a date in "yyyy-mm-dd" format but I want to display the date in another format : "dd/mm/yyyy" (french display).
Is there a good tip to do that with Datebox for jQuery Mobile (an option I didn't see ?)
I think I have to cheat in creating an input hidden with the good form format and another one with the format to display (and not submitted), but maybe a better solution exists.
Any ideas ?
Your best bet is to indeed use 2 inputs - but, it's pretty easy to do, and using a callback on the set event, you can even make datebox do the second format for you.
http://dev.jtsage.com/jQM-DateBox2/demos/script/split.html
(Note: I just added the demo, so you didn't miss it earlier)
Just a small addition
It should be "overrideDateFormat":"%d/%m/%Y" in the HTML inline options.
In http://dev.jtsage.com/jQM-DateBox2/demos/script/split.html it states "dateFormatOverride":"%d/%m/%Y"} however this is incorrect and doesn't work. Just a heads up for anyone else with this issue.
Yes you need to use this method.
<!-- fix american date formatting -->
<script type="text/javascript">
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
'overrideDateFormat': '%d/%m/%Y',
'overrideHeaderFormat': '%d/%m/%Y'
});
</script>

Get the previous month from today's date

Is there a way in lwuit1.4 to get the the last month from todays date? I tried using the add method, but it is not there in lwuit's calendar api.
That's unrelated to LWUIT, its the java.util.Calendar class from CLDC which is missing the add method. It does have the set method so you you can code something like that yourself. See the code for LWUIT's Calendar class where the arrows allow navigating between months.

Ajax Control Toolkit Date Picker - Is it possible to not have to select the day?

So I can set the date format on the Calendar Extender to it displays just the month, but you would still have to select the Year, then the Month, then the Day.
I would like to just select the Year, then the Month.
<cc2:CalendarExtender ID="DateOfReleaseCalendarExtender" runat="server"
TargetControlID="DateOfReleaseTextBox"
Format="MMMM yyyy" />
That is not a built-in feature, no. You'll have to extend it yourself. I would probably hook into the Javascript events--whichever one you think makes sense in your situation.
This requires patching the CalendarExtender part of the AjaxControlToolkit assembly.
I found a blog post that explains how to do something very similar to what you are trying to do: Patching the CalendarExtender Control