Basically I want to take date from one field and then increment day and set it to another date field.
This is kind of psuedo-code:
var date1 = $( '#date1' ).datepicker( 'getDate' );
var incrementDate = date1 + 1 //increment day
$( '#date2' ).datepicker('setDate', incrementDate );
var date1 = $('#date1').datepicker('getDate');
var date = new Date( Date.parse( date1 ) );
date.setDate( date.getDate() + 1 );
var newDate = date.toDateString();
newDate = new Date( Date.parse( newDate ) );
$('#date2').datepicker('setDate', newDate );
var date = new Date($('#date1').datepicker('getDate'));
date.setDate(date.getDate() - 1);
$('#date1').datepicker('setDate', date);
Related
I have implemented a bootstrap datepicker for policy start, so that I want to show user to select dates from current month and next month only.
Can anyone tell me how is it possible in bootstrap datepicker?
$(".policy-start-dp").datepicker({
});
You need to set the minimum and maximum values of the date picker
//Get Current Date
var date = new Date();
//Create Variable for first day of current month
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
//Create variable for last day of next month
var lastDay = new Date(date.getFullYear(), date.getMonth() + 2, 0);
$( "#datepicker" ).datepicker({
minDate: firstDay,
maxDate: lastDay
});
Hope that helps :)
no need to set start and end date just pust the "startDate" code is below.
var changeDateFormat = () => {
if ($(fileMonths).parent().parent().hasClass('sandbox-container')) {
$('#fileMonths').datepicker({
autoclose: true,
minViewMode: 1,
startDate: '0m',
format: "mm/yyyy"
});
}
};
date picker months
So far, I have this code:
var seconds = 0
var minutes = 0
var hours = 0
var secondsUntilMidnight = 0
var minutesUntilMidnight = 0
var hoursUntilMidnigh = 0
var day = 0
var month = 0
var year = 0
//xvar day = [ hours, minutes, seconds]
var damian = "DayofWeek"
var monday = true
var tuesday = false
var wednesday = true
var thursday = false
var friday = false
var saturday = true
var sunday = false
var currentDay = 0
var nextworkingday = 0
var dayOfTheWeek = [Bool]()///Var collecting bools for each day
var dayOfTheWeekText = [String]()///Collecing name for each day
where the weekday Bool values are adjustable. I want the app to detect the current time and date, and calculate the time until the next day that is set as true.
This is what I have tried so far:
let now = Date()
let calendar = Calendar.current
let components = DateComponents(calendar: calendar, hour:11 , minute : 28 ) // <- 17:00 = 5pm
// let components2 = DateComponents(calendar: calendar day : 1, _)
let next5pm = calendar.nextDate(after: now, matching: components, matchingPolicy: .nextTime)!
print (now )
let next = calendar.nextDate(after: now, matching: components, matchingPolicy: .nextTime)!
let diff = calendar.dateComponents([.hour, .minute, .second ], from: now, to: next5pm)
///Second time checker
let calendar2 = Calendar.current
let components2 = DateComponents(calendar: calendar2, hour:00 , minute : 00 ) // <- 17:00 = 5pm
let next1pm = calendar2.nextDate(after: now, matching: components2, matchingPolicy: .nextTime)!
let next2 = calendar2.nextDate(after: now, matching: components2, matchingPolicy: .nextTime)!
let diff2 = calendar2.dateComponents([.hour, .minute, .second ], from: now, to: next1pm)
secondsUntilMidnight = diff2.second!
minutesUntilMidnight = diff2.minute!
hoursUntilMidnigh = diff2.hour!
hours = diff.hour!
minutes = diff.minute!
seconds = diff.second!
But it only calculates the time until a certain time the NEXT day while I want it to detect. For example, if today is Monday, and the next day is Wednesday and start a countdown to a seleced time on that day.
Any help would be appreciated. Thanks.
Update
Ignore the code, its just an example of what i have done to try to give the app the functionality that is needed!
In this viewport, i want the code to check what day it is, see when another day that is 'true' and calculate time until then
Swift date has a method timeIntervalSince which will calculate the TimeInterval (ie number of seconds) between two dates. You can then use DateComponentsFormatter to transform the interval into a formatted string containing whatever units you want.
I am trying to allow customer within age 18-50 in my application and I am using jqueryui datepicker.
I am not getting a way for events to be employed for this!
Any help will be much appreciated!
While investigating, I got a way to do this.
jQuery( "#datepicker" ).datepicker({
maxDate: '-18y',
minDate: '-68y',
});
where #datepicker is my selector.
If there's a better way to do the same, then comments are most welcome!
try this .. its another way...
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd = '0'+dd
}
if(mm<10) {
mm = '0'+mm
}
today = mm + '/' + dd + '/' + yyyy;
$('input').datepicker({
minDate: 'today-18250',
maxDate: 'today-6570',
beforeShowDay: function(date){
var str = jQuery.datepicker.formatDate('yy-mm-dd', date);
var minDateArr = $(this).datepicker( "option", "minDate" ).split('/')
var minDate = new Date(minDateArr[2],minDateArr[0]-1,minDateArr[1]);
if ($.inArray(str) != -1){
return [false, 'special']
}
else if(date < minDate ){
return [false, 'not-special']
}
else{
return [true,"special"];
}
}
});
I am having an issue with converting a string to NSDate in Xcode: I am trying to get the current date, subtract one day and set the hour to noon. This is how I'm going about it (thw two snippets are in different functions):
let date = NSDate();
let dateFormatter = NSDateFormatter()
//var locale = NSLocale(localeIdentifier: "en_US_POSIX")
//dateFormatter.locale = locale
dateFormatter.dateFormat = "dd/mm/yyyy HH:mm"
dateFormatter.timeZone = NSTimeZone.localTimeZone()
var string = dateFormatter.stringFromDate(date)
var localdate = dateFormatter.dateFromString(string)
var localString = dateFormatter.stringFromDate(localdate!)
var calendar = NSCalendar.currentCalendar()
var components = calendar.components(NSCalendarUnit.HourCalendarUnit | NSCalendarUnit.DayCalendarUnit | NSCalendarUnit.MonthCalendarUnit | NSCalendarUnit.YearCalendarUnit, fromDate: localdate!)
self.dateCriteriaHour = components.hour
self.dateCriteriaDay = components.day
self.dateCriteriaMonth = components.month
self.dateCriteriaYear = components.year
This seems to work: I get the current date's components. Then I do this:
var day = String(self.dateCriteriaDay - 1)
var month = String(currentMonth)
var year = String(self.dateCriteriaYear)
var hour = "12:00"
var date = year + "/" + month + "/" + day + " " + hour
var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy/m/dd HH:mm"
var criteriaDate = dateFormatter.dateFromString(date)
println(date)
println(NSDate())
println(criteriaDate)
This is where things get strange. Here is the output to the console:
2015/7/11 12:00
2015-07-12 15:21:42 +0000
Optional(2015-01-11 04:00:00 +0000)
I understand that the device stores time in its selected time zone so I'm not too worried about that. What puzzles me is basically that everything is right except for the month, even though it comes out right in the string.
Any idea as to why this is happening?
Your dateformat is wrong.
dd/mm/yyyy HH:mm
^^ ^^
You use mm two times. A lower case m means minutes, an upper case M means month. So your dateFormat should be dd/MM/yyyy HH:mm
I have two strings:
String date = "2011-11-11"
String time="11:00 PM"
i want to merge this date and time and convert them into a long, similar to System.currentTimeMillis().
try this it is working fine
String inputDate=date+" "+time ;;
long parsedDate = HttpDateParser.parse(inputDate);//inputDate should 2011-12-11 11:10:00 PM" formate
System.out.println("========================="+parsedDate);
Date date=new Date(parsedDate);
SimpleDateFormat date1=new SimpleDateFormat("yyyy-mm-dd hh:mm aa");
String opdate=date1.format(date);
System.out.println("========================="+opdate);
Use SimpleDateFormat and parse the String into a Date.
When you have Date you can get .getTime() what's a long
http://download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html
NOT TESTED!!
String date = "2011-11-11";
String time = "11:00 PM";
String toParse = date + " " + time;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm aa");
try {
Date parse = sdf.parse(toParse);
parse.getTime();
} catch (ParseException ex) {
}
String dateTime = "2011-11-11 " + time;
DateFormat formatter ;
Date date ;
formatter = new SimpleDateFormat("dd-MMM-yy HH:MM");
date = (Date)formatter.parse(dateTime );
long time = date.getTime();
I found this SO post in the same lines.
String date =date+time ;
SimpleDateFormat fmt = new SimpleDateFormat("MM-dd-yyyy HH:mm");
Date myDate = fmt.parse(date);
System.out.println(myDate); //Mon Jun 04 07:05:00 EDT 2007
long timestamp = myDate.getTime();