Date Object to Number Object

Results 1 to 2 of 2

Thread: Date Object to Number Object

  1. #1
    Join Date
    Dec 1969

    Default Date Object to Number Object

    I am trying to take the hour of a date object and make it a number in a different varible.<BR><BR>StartHour = parseFloat(bob.getHours());<BR><BR>but when I write it back to the screen like this:<BR><BR>Response.Write(StartHour);<BR><BR>I get this:<BR><BR>12:04:03 PM<BR><BR>Instead of giving me just the hour as a number object im just passing around the date object to various varibles. What am I doing wrong?<BR><BR>---------------------------------<BR>complete code as it is now<BR>---------------------------------<BR><BR>&#060;%@ language=javascript %&#062;<BR>&#060;%<BR>var sql = "SELECT * FROM [BUWeb$]"; //sql query<BR>var file = "/BUWeb.xls"; //soon to be query string<BR>var oConnExcel = Server.CreateObject("ADODB.Connection");<BR>var Excel = "Provider=Microsoft.Jet.OLEDB.4.0;"+"Data Source=&#039;"+Server.mappath(file)+"&#039;;Extend ed Properties=Excel 8.0;";+";Extended Properties=Excel 8.0;";<BR>var rsStats = Server.CreateObject("ADODB.Recordset");<BR>oConnEx cel.Open(Excel);<BR>rsStats = oConnExcel.Execute(sql);<BR>rsStats.MoveFirst;<BR> <BR><BR>while(!rsStats.EOF){<BR>var StartHour;<BR>var StartMinute;<BR>var SecstoKill;<BR>Response.Write(rsStats("FirstEservi cePSTtime"));<BR>Response.Write("<BR>");<BR>var bob = new Date(rsStats("FirstEservicePSTtime").value);<BR>St artHour = parseFloat(bob.getHours());<BR>StartMinute = bob.getMinutes();<BR>if(StartHour&#062;17){<BR> SecstoKill = ((24-StartHour)*60)*60;<BR> }<BR>Response.Write(SecstoKill);<BR>rsStats.MoveNe xt;<BR>}<BR><BR>oConnExcel.Close;<BR>oConnExcel = null;<BR>rsStats = null;<BR><BR><BR>%&#062;<BR>

  2. #2
    Join Date
    Dec 1969

    Default I don't believe you...

    Well, I believe you may have seen something strange. But the code you show sure doesn&#039;t have any problems other than a couple of (I think) irrelevant coding errors.<BR><BR>********** ********<BR><BR>var bob = new Date(rsStats("FirstEservicePSTtime").value);<BR><B R>You should *NOT* need to do that! If the DB field is a Date/Time value, then just do:<BR><BR>var bob = rsStats("FirstEservicePSTtime");<BR><BR>And you should automatically get a Date object.<BR><BR>********** ********<BR><BR>StartHour = parseFloat(bob.getHours());<BR><BR>Why do you call parseFloat? The getHours() method on a Date object is *guaranteed* to return an INTEGER in the range 0 to 23.<BR><BR>*********************<BR><BR>if(StartHo ur&#062;17){<BR>&nbsp; &nbsp; SecstoKill = ((24-StartHour)*60)*60;<BR>}<BR>Response.Write(SecstoKi ll);<BR><BR>OOoooookkkkaaaaayy. And what happens if StartHour is *NOT* greater than 17??? What will SecstoKill contain? Hint: It won&#039;t be zero, since you didn&#039;t initialize it. <BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts