Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this is my code.



C#
var elements = document.querySelectorAll('.date-time');

for(var i = 0; i < elements.length; i++) {
    var from = elements[i].getAttribute('data-from');
    var to = elements[i].getAttribute('data-to');
    var bigger = to;
    if(new Date(from) > new Date(to)) {
       bigger = from;
    }
    elements[i].innerHTML = bigger;
}


and the output --> 2015/3/16 23:59:00

but i want the output like--> 16 - 17 Jan 2015
09:20 AM - 11:59 PM

how to achieve this output.
Posted

1 solution

JavaScript
//From date
var fromdate = $("#data-from").val(); 
var from_date = new Date(fromdate);
//Todate	
var todate =  $("#data-to").val();
var to_date = new Date(todate); 
 
if(from_date > to_date)
{
	---
}
 
//you can get 
var dd = to_date.getDate(); //yields day
var MM = to_date.getMonth(); //yields month
var YY = to_date.getFullYear(); //yields year


//Find the required date formats with code
https://jqueryui.com/datepicker/#date-formats[^]
 
Share this answer
 
Comments
ap@2387 23-Jun-15 6:14am    
not working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900