[flexcoders] Re: What is the best way to add a day to a date?

2008-02-07 Thread rmarples
Sorry, first post didn't come through properly. Try this:

var origDateString:String = 2008/12/31;
var dateItems:Array = origDateString.split(/);
var newDate:Date = new Date(dateItems[0], Number(dateItems[1])-1, 
Number(dateItems[2])+1);
var newDateString:String = newDate.getFullYear() + / + (newDate.getMonth() + 
1) + / 
+ newDate.getDate();

Ryan

--- In flexcoders@yahoogroups.com, Mark [EMAIL PROTECTED] wrote:

 I'm getting dates in my XML formatted like this:
 
 2008/12/20
 
 In some cases in my Flex app I need to add 1 day to that date.  What 
 is the best way to do that?  Right now I'm working it out this way:
 
 s = chartDates.getItemAt(0).globalDeadline;
 a = s.split(/);
 newDate = a[0]+/+a[1]+/+(Number(a[2])+1);
 
 But I'm pretty sure this isn't right.
 
 Can someone help out with the code?
 
 Thanks
 -M






Re: [flexcoders] Re: What is the best way to add a day to a date?

2008-02-07 Thread Scott Melby

seems doing this you could easily end up with 2008/12/32 :)

I'd parse the data, then create a Date object.  Adding a day to a Date 
should be as simple as


myDate.time += (24 * 60 * 60 * 1000);

hth
Scott

Scott Melby
Founder, Fast Lane Software LLC
http://www.fastlanesw.com



rmarples wrote:



--- In flexcoders@yahoogroups.com 
mailto:flexcoders%40yahoogroups.com, Mark [EMAIL PROTECTED] wrote:


 I'm getting dates in my XML formatted like this:

 2008/12/20

 In some cases in my Flex app I need to add 1 day to that date. What
 is the best way to do that? Right now I'm working it out this way:

 s = chartDates.getItemAt(0).globalDeadline;
 a = s.split(/);
 newDate = a[0]+/+a[1]+/+(Number(a[2])+1);

 But I'm pretty sure this isn't right.

 Can someone help out with the code?

 Thanks
 -M


 


[flexcoders] Re: What is the best way to add a day to a date?

2008-02-07 Thread rmarples

--- In flexcoders@yahoogroups.com, Mark [EMAIL PROTECTED] wrote:

 I'm getting dates in my XML formatted like this:

 2008/12/20

 In some cases in my Flex app I need to add 1 day to that date.  What
 is the best way to do that?  Right now I'm working it out this way:

 s = chartDates.getItemAt(0).globalDeadline;
 a = s.split(/);
 newDate = a[0]+/+a[1]+/+(Number(a[2])+1);

 But I'm pretty sure this isn't right.

 Can someone help out with the code?

 Thanks
 -M





[flexcoders] Re: What is the best way to add a day to a date?

2008-02-07 Thread Doug Lowder
It's not that simple, because of Daylight Savings Time.  Try the 
following on a machine with the timezone set to something that 
follows DST:

var ms:Number = 24*60*60*1000;
var d:String = 2008/11/02;
var newDate:Date = new Date(Date.parse(d)+ms);

You'll get the same day, 2008/11/02, because Nov 2 2008 will be a 25-
hour day in some locations due to the clocks being set back.  You'd 
need to convert to UTC before doing the math, or check the timezone 
of the dates with getTimezoneOffset() and adjust accordingly if 
needed.


--- In flexcoders@yahoogroups.com, Kevin Aebig [EMAIL PROTECTED] wrote:

 Yeah, that works too... =]
 
 !k
 
 -Original Message-
 From: flexcoders@yahoogroups.com 
[mailto:[EMAIL PROTECTED] On
 Behalf Of Muzak
 Sent: Thursday, February 07, 2008 4:16 PM
 To: flexcoders@yahoogroups.com
 Subject: Re: [flexcoders] What is the best way to add a day to a 
date?
 
 or:
 
 var ms:Number = 24*60*60*1000;
 var d:String = 2008/12/20;
 var newDate:Date = new Date(Date.parse(d)+ms);
 
 
 - Original Message - 
 From: Kevin Aebig [EMAIL PROTECTED]
 To: flexcoders@yahoogroups.com
 Sent: Thursday, February 07, 2008 6:19 PM
 Subject: RE: [flexcoders] What is the best way to add a day to a 
date?
 
 
  Create a date object with the string, than add the day to it like 
this:
  
  
  
  newDate = new Date(a[0], a[1], a[2]);
  
  newDate.seconds += 8640; // seconds in a day or (60*60*24)
  
  
  
  !k 
 
 
 
 --
 Flexcoders Mailing List
 FAQ: 
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
 Search Archives: http://www.mail-archive.com/flexcoders%
40yahoogroups.com 
 Yahoo! Groups Links





Re: [flexcoders] Re: What is the best way to add a day to a date?

2008-02-07 Thread Muzak
Works fine here using 2008/11/02 as the starting date, but that's probably 
because winter time kicks in on a different date here 
(which I don't know).
Summer time kicks in on 2008/03/30 so I tried that instead.

Notice that the new date has 1 hour added.
I guess when using the winter time it would subtract 1 hour, resulting in the 
same date as the original.

// tested
var ms:Number = 24*60*60*1000;
var d:String = 2008/03/30;
var newDate:Date = new Date(Date.parse(d)+ms);
trace(new Date(Date.parse(d)));
trace(newDate);

//output
Sun Mar 30 00:00:00 GMT+0100 2008
Mon Mar 31 01:00:00 GMT+0200 2008

Gotta luv date manipulations.. fun fun..

- Original Message - 
From: Doug Lowder [EMAIL PROTECTED]
To: flexcoders@yahoogroups.com
Sent: Friday, February 08, 2008 1:56 AM
Subject: [flexcoders] Re: What is the best way to add a day to a date?


It's not that simple, because of Daylight Savings Time.  Try the
following on a machine with the timezone set to something that
follows DST:

var ms:Number = 24*60*60*1000;
var d:String = 2008/11/02;
var newDate:Date = new Date(Date.parse(d)+ms);

You'll get the same day, 2008/11/02, because Nov 2 2008 will be a 25-
hour day in some locations due to the clocks being set back.  You'd
need to convert to UTC before doing the math, or check the timezone
of the dates with getTimezoneOffset() and adjust accordingly if
needed.





--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

* To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/

* Your email settings:
Individual Email | Traditional

* To change settings online go to:
http://groups.yahoo.com/group/flexcoders/join
(Yahoo! ID required)

* To change settings via email:
mailto:[EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED]

* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]

* Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/