From: bruce on
The input for this this code is YearT=2010, MonthIndex=3, DayT = 27,
Start_HourT = 22, Start_MinutesT=15,
End_HourT = 20, End_MinutesT = 15

var InputStart = new Date();
var InputEnd = new Date();

InputStart = Date(YearT, MonthIndex, DayT, Start_HourT,Start_MinutesT,
0,0);
InputEnd = Date(YearT, MonthIndex, DayT, End_HourT, End_MinutesT,0,0);

alert(Start_HourT + ":" + End_HourT); // output is 22:20 Correct
output

alert("==: " + (InputStart == InputEnd)); // Output is true?? Output
Not Correct

How am I "Misusing" JavaScript???

Thanks....
From: Stefan Weiss on
On 28/04/10 05:11, bruce wrote:
> The input for this this code is YearT=2010, MonthIndex=3, DayT = 27,
> Start_HourT = 22, Start_MinutesT=15,
> End_HourT = 20, End_MinutesT = 15
>
> var InputStart = new Date();
> var InputEnd = new Date();
>
> InputStart = Date(YearT, MonthIndex, DayT, Start_HourT,Start_MinutesT,
> 0,0);
> InputEnd = Date(YearT, MonthIndex, DayT, End_HourT, End_MinutesT,0,0);
>
> alert(Start_HourT + ":" + End_HourT); // output is 22:20 Correct
> output
>
> alert("==: " + (InputStart == InputEnd)); // Output is true?? Output
> Not Correct

If you want to call Date as a constructor, you need to write

var InputStart = new Date(...); // note the 'new' operator

Without 'new', Date() will ignore its arguments and return a string
representing the current date/time instead of a Date object.


--
stefan
From: bruce on
On Apr 28, 2:52 am, Stefan Weiss <krewech...(a)gmail.com> wrote:
> On 28/04/10 05:11, bruce wrote:
>
>
>
> > The input for this this code is YearT=2010, MonthIndex=3, DayT = 27,
> > Start_HourT = 22, Start_MinutesT=15,
> > End_HourT = 20, End_MinutesT = 15
>
> > var InputStart = new Date();
> > var InputEnd = new Date();
>
> > InputStart = Date(YearT, MonthIndex, DayT, Start_HourT,Start_MinutesT,
> > 0,0);
> > InputEnd = Date(YearT, MonthIndex, DayT, End_HourT, End_MinutesT,0,0);
>
> > alert(Start_HourT + ":" + End_HourT); // output is 22:20 Correct
> > output
>
> > alert("==: " + (InputStart == InputEnd)); // Output is true?? Output
> > Not Correct
>
> If you want to call Date as a constructor, you need to write
>
>   var InputStart = new Date(...);    // note the 'new' operator
>
> Without 'new', Date() will ignore its arguments and return a string
> representing the current date/time instead of a Date object.
>
> --
> stefan

Thank you. That fixed my problem with the Date constructor.
What am I doing wrong here???

Thank you..

Bruce
From: johncoltrane on
Le 28/04/10 14:35, bruce a �crit :
> On Apr 28, 2:52 am, Stefan Weiss<krewech...(a)gmail.com> wrote:
>> On 28/04/10 05:11, bruce wrote:
>>
>>
>>
>>> The input for this this code is YearT=2010, MonthIndex=3, DayT = 27,
>>> Start_HourT = 22, Start_MinutesT=15,
>>> End_HourT = 20, End_MinutesT = 15
>>
>>> var InputStart = new Date();
>>> var InputEnd = new Date();

Here InputStart and InputEnd are both assigned a Date object with the
time at the moment of assignment :

typeof(InputStart) returns "object", same for InputEnd, you can now use
InputStart.getDay() or any other method of Date.

>>
>>> InputStart = Date(YearT, MonthIndex, DayT, Start_HourT,Start_MinutesT,
>>> 0,0);
>>> InputEnd = Date(YearT, MonthIndex, DayT, End_HourT, End_MinutesT,0,0);

Here you overwrite the Date object assigned to the InputStart and
InputEnd with what is returned by a call to
Date(like,stefan,wrote,whatever,arguments,you,put,here,won't,be,honoured) :
a string representing the time at the moment of assignment.

typeof(InputStart) returns "string", same for InputEnd.

Because all this happens within a few milliseconds both strings are
equal (the string is rounded to the second) which is why you get "true"
if you test for their equality with (InputStart == InputEnd).

>>
>>> alert(Start_HourT + ":" + End_HourT); // output is 22:20 Correct
>>> output
>>
>>> alert("==: " + (InputStart == InputEnd)); // Output is true?? Output
>>> Not Correct
>>
>> If you want to call Date as a constructor, you need to write
>>
>> var InputStart = new Date(...); // note the 'new' operator
>>
>> Without 'new', Date() will ignore its arguments and return a string
>> representing the current date/time instead of a Date object.
>>
>> --
>> stefan
>
> Thank you. That fixed my problem with the Date constructor.
> What am I doing wrong here???
>
> Thank you..
>
> Bruce


--
(�l�)
From: RobG on
On Apr 28, 1:11 pm, bruce <bruc...(a)bellsouth.net> wrote:
> The input for this this code is YearT=2010, MonthIndex=3, DayT = 27,
> Start_HourT = 22, Start_MinutesT=15,
> End_HourT = 20, End_MinutesT = 15

By convention, variable names starting with a capital letter signify
constructors or, where all characters are upper case, constants. Code
is much easier to read if neatly indented and, when posted to a news
group, manually wrapped at about 70 characters.

>
> var InputStart = new Date();
> var InputEnd = new Date();

There's no point initialising variables with a value that you
immediately overwrite.

> InputStart = Date(YearT, MonthIndex, DayT, Start_HourT,Start_MinutesT,
> 0,0);
> InputEnd = Date(YearT, MonthIndex, DayT, End_HourT, End_MinutesT,0,0);

Here you overwrite the intial values assigned to these variables,
trivialising in the initial assignment. In ECMAScript, variables do
not have a type (their values do), you can assign any type to any
variable so there is no need to initialise them if you don't want to.

> alert(Start_HourT + ":" + End_HourT); // output is 22:20 Correct
> output
>
> alert("==: " + (InputStart == InputEnd)); // Output is true?? Output
> Not Correct

Consider (wrapped for posting):

var yearT=2010,
monthIndex=3,
dayT = 27,
start_HourT = 22,
start_MinutesT=15,
end_HourT = 20,
end_MinutesT = 15,
inputStart = new Date(yearT, monthIndex, dayT,
start_HourT, start_MinutesT, 0, 0),
inputEnd = Date(yearT, monthIndex, dayT, end_HourT,
end_MinutesT, 0, 0);

alert(inputStart == inputEnd); // false


--
Rob