Ok there is a pretty complicated thing I need done in Flash CS4 with as3. I've looked around the web but I couldn't find much useful info.
Basically I have 3 ComboBoxes, one for the UTC date, another for the UTC month and another for the UTC year. I need it to be done so that the comboboxes will show the dates inbetween a set date (a date which I initially set in the flash script) and the current UTC date. For example, if I put the set date as 1st of Feb 2013, and the current date is 4th of March, I want the user to only be able to select February and March in the 'month' combobox. If they select February, then the available dates in the 'date' combobox should be 1 - 28, but if March is selected then only 1 - 4 should be available. This should be able to update every day automatically, so for example on March 5th, the number 5 should be added so it should be 1 - 5 available on the 'date' combobox if March is selected and so on...
I honestly have no idea how to go about this, but I really need it done one way or another. If anyone could help me I would be thankful.
When you select a new month, your two boundary dates can update accordingly, then this function can help you generate the date in between
private function test():void
{
var date1:Date = new Date(2012, 11, 25);
var date2:Date = new Date();
generateDateBetween(date1, date2);
}
private function generateDateBetween(date1:Date, date2:Date):void
{
for (var i:Number = date1.time; i < date2.time; i+= 3600*24*1000)
{
var date:Date = new Date();
date.time = i;
trace(date);
}
}
Related
We need to determine "first week of the month". As far as I've read there's no ISO standard for this but I've encountered two definitions:
First week of the month is the week that contains 1st day of the month.
First week of the month is the first full week of that month.
In our application, we are frequently using the ISO week format which is like '2022-W09' that means (obviously) 9th week of 2022.
So, we can easily find first week of the year '2022-W01' and the dates it includes: from 2022-01-03 to 2022-01-09 (according to HTML5 input type week).
And this shows me that (even though I liked and implemented the first definition in the first place) we should accept the second definition because HTML follows that.
As a conclusion, I need an algorithm to find "first week of the month" which I accept to be "the first full week of that month" (2nd definition).
Hereby I put the code I use to find "the week that contains 1st day of the month" which is "first week of the month" in the 1st definition above. You may modify it to suggest a solution:
public function isFirstWeekOfMonth()
{
$carbon = Carbon::create()->setISODate(2022, 9);
$startOfWeekCarbon = $carbon->startOfWeek();
$endOfWeekCarbon = $carbon->endOfWeek();
$startOfMonthCarbon = $carbon->endOfWeek()->startOfMonth();
return $startOfMonthCarbon->betweenIncluded($startOfWeekCarbon, $endOfWeekCarbon);
}
Depending of what you consider a first day of the week, you can do it like this:
I will consider that you consider Monday as a first day of the week.
// Create a date (carbon)
$carbon = Carbon::create()->setISODate(2022, 9);
// Find the first Monday in the month for given date. For Tuesday use 2, Wednesday 3 ...
$firstMondayInTheMonth = $carbon->firstOfMonth(1); // This is also a start of that week
// Find the end of the week.
$endOfTheWeek = $firstMondayInTheMonth->endOfWeek();
In the image below you can see how it works in practice:
With that, you have a first Monday in the month - which means first start of the week, and using endOfWeek you can get Sunday of that week (end of the first week). Using betweenIncluded you can figure out if one date is between that Monday and Sunday of first week in that month.
I have updated my function according to the accepted answer:
public function isFirstWeekOfMonth()
{
$carbon = Carbon::create()->setISODate(2022, 10);
$startOfWeekDate = $carbon->startOfWeek()->format('Y-m-d');
$endOfWeekDate = $carbon->endOfWeek()->format('Y-m-d');
$firstMondayInMonth = $carbon->firstOfMonth(1);
return $firstMondayInMonth->betweenIncluded($startOfWeekDate, $endOfWeekDate);
}
And I have tested it, it is working as expected.
For this week (2022-W09), it's false:
For next week (2022-W10), it's true:
Note: I realized that I was using betweenIncluded() function wrongly, it is accepting dates as parameters, not Carbon objects.
=== FINAL ===
I think I have made the function its best which has the simplest algorithm:
"If the first Monday of the month is equal to first date of this week, then it is the first week of the month."
public function isFirstWeekOfMonth()
{
$currentWeekCarbon = Week::carbon($this->week);
$startOfWeekCarbon = $currentWeekCarbon->startOfWeek();
$firstMondayInMonthCarbon = $currentWeekCarbon->firstOfMonth(1);
return $startOfWeekCarbon->equalTo($firstMondayInMonthCarbon);
}
Again I have tested it, it is working as expected.
I need help to create a drop down for day to pick from. Is there a way to do this? Thanks
using javascript you can populate that field
toget number of days in that month can use
var date = new Date()
which is javascript function which will give you today's date
and then use
date.getMonth()
date.getYear()
to get today's month and year
//Month is 1 based
function daysInMonth(month,year) {
return new Date(year, month, 0).getDate();
}
//July
daysInMonth(7,2009); //31
//February
daysInMonth(2,2009); //28
daysInMonth(2,2008); //29
I'm trying to write a script which is supposed to send out an email and create two calender entries when submitting a form. To be honest, this is my first script and I am very happy that the email is send out and the calender entries are working as well. The thing which gives me a headache is to subtract 5 days (actually x days) from a defined date.
First I thought I could simply do something like
var liveday = e.values[2];
var newday = liveday-5;
well, this didn't work :-)
I tried more:
var newtime = new Date(liveday);
var yr = newtime.getYear();
var dt = newtime.getDay();
var mt = newtime.getMonth();
var dtnew = dtnew.setDate(mt, dt-5, yr);
But here I received 1418256000000 whereas liveday = 12/01/2014. Not sure why days were added, rather than subtracted.
I am quite confused here and the answer can't be that hard.
I just want to subtract 5 days from 12/01/2014 to receive 11/27/2014.
Thanks for having a look
the comment sends you to a rather complicated serie of codes... there is a far more simple way to get that, here is the code :
function test() {
Logger.log('today= '+new Date()+' and 5 days ago is '+subDaysFromDate(new Date(),5));
}
function subDaysFromDate(date,d){
// d = number of day ro substract and date = start date
var result = new Date(date.getTime()-d*(24*3600*1000));
return result
}
Logger result :
[13-11-18 23:39:50:364 CET] today= Mon Nov 18 2013 23:39:50 GMT+0100 (CET) and 5 days ago is Wed Nov 13 2013 23:39:50 GMT+0100 (CET)
if you want to get the date in the form dd/mm/yyyy use Utilities.formatDate(date, timeZone, 'dd/MM/yyyy), see doc here
We have an application in which the user has to enter a date who's value is no more than 30 days after the the current date (the date on which the user uses the application). This is a Flash application, therefore I need a way to add 30 days to the current date, and get the right date. Something like in JavaScript:
myDate.setDate(myDate.getDate()+30);
Or in C#:
DateTime.Now.Add(30);
Is there such a thing in ActionScript?
While the other answers will work im sure, it is as easy as doing:
var dte:Date = new Date();
dte.date += 30;
//the date property is the day of the month, so on Sept. 15 2009 it will be 15
This will even increment the month if necessary and year as well. You can do this with the month and year properties as well.
I suggest that you look here: How can you save time by using the built in Date class?.
It should be something like this:
var date:Date = new Date();
date.setDate(date.date + 30);
My TimeSpan class might prove useful here (it's a port of the .NET System.TimeSpan):
var now : Date = new Date();
var threeDaysTime : Date = TimeSpan.fromDays(3).add(now);
#Zerata
Adding milliseconds directly will not work if dates are across day light saving change...
However, you can add seconds directly:
var date: Date = new Date();
date.seconds += 86400;
=> this works even if dates are across DLS change.
Maurice
I'm writing the code from the top of my head, without compiling it, but I'd use getTime(). Something like:
var today : Date = new Date();
var futureDate : Date = new Date();
futureDate.setTime(today.getTime() + (1000 * 60 * 60 * 24 * 30));
1000 * 60 * 60 * 24 * 30 = milliseconds * seconds * minutes * hours * days
Makes sense?
Hi I'm having a problem setting a date in as3
here is the code i'm using
var endDate = new Date(2009,9,10);
trace (endDate);
the trace statement always shows the date as 1 month further on the the date I have added eg
10th Oct 2009 instead of 10th september 2009
Is there a way around this?
The month is 0 index.
var endDate = new Date(2009,9-1,10);
Yeah, dates are zero indexed in AS, so you'll need to subtract one
0 indexed like the other said. Try and take a look at this post for more tips on the date object:
How can you save time by using the built in Date class?
It might be because you are converting strings to numbers.
(Implicit coercion of a value of type String to an unrelated type Number.)
If you just make it:
var day:Number=parseInt("10");
var month:Number=parseInt("9");
var year:Number=parseInt("2009");
var adjMonth =month-1;
var endDate = new Date(year,adjMonth,day);
trace(endDate.toString());
It'll work fine.