[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 518
  • Last Modified:

Set DateTimePicker value

OK, I am using the MS DTpicker control in my web page. When you view the parameters for it you see the param tag for the Value. This value is ~ lets say 37088 that equates to 7/16/2001 . What are the calculations to arrive at this value and to be able to set it using ASP.

Thanks Randall
0
rcashon
Asked:
rcashon
  • 11
  • 3
  • 3
  • +2
1 Solution
 
thunderchickenCommented:
37088 / 365 = 101.xxxxx

I believe they count from 1/1/1900 + 37088 days is 7/16/2001

Try

<%
  Response.Write (datediff("d","1/1/1900","7/16/2001"))


%>

it gives you 37086
0
 
rcashonAuthor Commented:
I tested that and the values were 2 days off.
37000 = 4/19/2001
37086 = 7/14/2001
37185 = 10/21/2001

Close ,but not quite.

r
0
 
thunderchickenCommented:
This value is ~ lets say 37088 that equates to 7/16/2001 .

37086 = 7/14/2001

Are you sure according to what you posted?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
rcashonAuthor Commented:
ThunderChicken,
   Yes, I verified my numberson this. I am still working on the calculations. It just does not seem right. THey could not do it like a normal person would could they.
0
 
damienmCommented:
It does seem strange but basically you have to set value=
DateDiff("d", "1/1/1900", Now) + 2 to get today's date.
0
 
rcashonAuthor Commented:
ThunderChicken,
   Yes, I verified my numberson this. I am still working on the calculations. It just does not seem right. THey could not do it like a normal person would could they.
0
 
rcashonAuthor Commented:
That is what I have been getting to work. I dont know why the calculat ion is like that, but it does work with the "+ 2" . OK, sort of. ? Have either of you used this in a web page? the more testing that I do the more strange things happen with this. I can get it loaded in the page and select a value which I can get passed over to a review screen, but if I press the back button the value in the calendar reverts back to the base value when the calendar page was first loaded. It does not know how to maintain state for ####. I like the format of it being a drop down and all, but if anyone knows of another  that actually works smoothly I will switch in a heart beat.
0
 
damienmCommented:
Yes I have used this before.

Basically in ASP load the control like below

dim dVal
dVal = DateDiff("d", "1/1/1900", Now) + 2

response.write "<OBJECT classid=clsid:20DD1B9E-87C4-11D1-8BE3-0000F8754DA1 id=DTPicker1 VIEWASTEXT><PARAM NAME='_ExtentX' VALUE='2646'><PARAM NAME='_ExtentY' VALUE='1323'><PARAM NAME='_Version' VALUE='393216'><PARAM NAME='MousePointer' VALUE='0'><PARAM NAME='Enabled' VALUE='1'><PARAM NAME='OLEDropMode' VALUE='0'><PARAM NAME='CalendarBackColor' VALUE='-2147483643'><PARAM NAME='CalendarForeColor' VALUE='-2147483630'><PARAM NAME='CalendarTitleBackColor' VALUE='-2147483633'><PARAM NAME='CalendarTitleForeColor' VALUE='-2147483630'><PARAM NAME='CalendarTrailingForeColor' VALUE='-2147483631'><PARAM NAME='CheckBox' VALUE='0'><PARAM NAME='CustomFormat' VALUE=''><PARAM NAME='DateIsNull' VALUE='0'><PARAM NAME='Format' VALUE='662831105'><PARAM NAME='UpDown' VALUE='0'><PARAM NAME='CurrentDate' VALUE='" & dVal & "'><PARAM NAME='MaxDate' VALUE='2958465'><PARAM NAME='MinDate' VALUE='-109205'></OBJECT>"

0
 
rcashonAuthor Commented:
That is what I have been getting to work. I dont know why the calculat ion is like that, but it does work with the "+ 2" . OK, sort of. ? Have either of you used this in a web page? the more testing that I do the more strange things happen with this. I can get it loaded in the page and select a value which I can get passed over to a review screen, but if I press the back button the value in the calendar reverts back to the base value when the calendar page was first loaded. It does not know how to maintain state for ####. I like the format of it being a drop down and all, but if anyone knows of another  that actually works smoothly I will switch in a heart beat.
0
 
rcashonAuthor Commented:
damienm,  
    Your source looks just like mine. The only difference is that I have mine in the HTML page rather that doing the response.write to load it. Also, have to tested it by setting the date in the calendar and then going to another page and coming back by clicking the back button? Check your values then. Either I am having a really bad coding day or it is not maintaining state.
 
0
 
damienmCommented:
I see what you mean

I am not sure, how to do this as activex controls are harder to work with in client side.  But if you can save a cookie in client side when the date changes then you can call this cookie in server side when the page is reloaded.

Something like

<%dim dVal
if Request.Cookies ("TimerVal") <> "" then
   dVal = DateDiff("d", "1/1/1900", Request.Cookies ("TimerVal")) + 2
else
   dVal = DateDiff("d", "1/1/1900", Now) + 2
end if

response.write "<OBJECT classid=clsid:20DD1B9E-87C4-11D1-8BE3-0000F8754DA1 id=DTPicker1 VIEWASTEXT><PARAM NAME='_ExtentX' VALUE='2646'><PARAM NAME='_ExtentY' VALUE='1323'><PARAM NAME='_Version' VALUE='393216'><PARAM NAME='MousePointer' VALUE='0'><PARAM NAME='Enabled' VALUE='1'><PARAM NAME='OLEDropMode' VALUE='0'><PARAM NAME='CalendarBackColor' VALUE='-2147483643'><PARAM NAME='CalendarForeColor' VALUE='-2147483630'><PARAM NAME='CalendarTitleBackColor' VALUE='-2147483633'><PARAM NAME='CalendarTitleForeColor' VALUE='-2147483630'><PARAM NAME='CalendarTrailingForeColor' VALUE='-2147483631'><PARAM NAME='CheckBox' VALUE='0'><PARAM NAME='CustomFormat' VALUE=''><PARAM NAME='DateIsNull' VALUE='0'><PARAM NAME='Format' VALUE='662831105'><PARAM NAME='UpDown' VALUE='0'><PARAM NAME='CurrentDate' VALUE='" & dVal & "'><PARAM NAME='MaxDate' VALUE='2958465'><PARAM NAME='MinDate' VALUE='-109205'></OBJECT>" %><META content="MSHTML 5.00.2919.6307" name=GENERATOR>



<SCRIPT LANGUAGE=vbscript>
function DTPicker1_change()
document.cookie = "TimerVal=" & DTPicker1.Value
end function
</SCRIPT>
0
 
rcashonAuthor Commented:
damienm,  
    Your source looks just like mine. The only difference is that I have mine in the HTML page rather that doing the response.write to load it. Also, have to tested it by setting the date in the calendar and then going to another page and coming back by clicking the back button? Check your values then. Either I am having a really bad coding day or it is not maintaining state.
 
0
 
thunderchickenCommented:
I think the reasoning behing the days are 2 off are probably because of uncalculated days that might have been added from today and 101 years ago.  Maybe they added an extra day here and there to make up for something astronomical?

I think it's clear those are the days and just adding a 2 to them will solve your problem
0
 
rcashonAuthor Commented:
damienm ,
 Let me tell you how I resolved this. OK the datediff solved the calc problems. Now for the reload issue... WHat I had to do was store my  new calendar variable as a session value when I went to the next page. When the user returns from the review page I test both  the old and the new session variables. if different I load the new value . I wrapped the calendar objects like this...
<html>
<body>
<% if session("newCalVal") <> "" then %>
    <OBJECT   ... all calendar parms ...>
          <PARAM NAME="CurrentDate" VALUE="<%=datediff("d","12/30/1899",session("EstCompDateNew"))%>">
    ......
    </OBJECT>
<% else %>

    <OBJECT   ... all calendar parms ...>
          <PARAM NAME="CurrentDate" VALUE="<%=datediff("d","12/30/1899",session("EstCompDateOLD"))%>">
    ......
    </OBJECT>
<% end if%>

You cant just switch out on the parms. It has to be the whole object. Anyway this worked out . I just hate cludgy code...



   
0
 
rcashonAuthor Commented:
damienm ,
 Let me tell you how I resolved this. OK the datediff solved the calc problems. Now for the reload issue... WHat I had to do was store my  new calendar variable as a session value when I went to the next page. When the user returns from the review page I test both  the old and the new session variables. if different I load the new value . I wrapped the calendar objects like this...
<html>
<body>
<% if session("newCalVal") <> "" then %>
    <OBJECT   ... all calendar parms ...>
          <PARAM NAME="CurrentDate" VALUE="<%=datediff("d","12/30/1899",session("EstCompDateNew"))%>">
    ......
    </OBJECT>
<% else %>

    <OBJECT   ... all calendar parms ...>
          <PARAM NAME="CurrentDate" VALUE="<%=datediff("d","12/30/1899",session("EstCompDateOLD"))%>">
    ......
    </OBJECT>
<% end if%>

You cant just switch out on the parms. It has to be the whole object. Anyway this worked out . I just hate cludgy code...



   
0
 
rcashonAuthor Commented:
Thunderchicken, yes I agree with you however it would have nice of the developer to use standard conventions for the calendar. Not counting the fact that the control is marked unsafe for scripting ... Someone had been out tooo  later the night before when they released that one...
0
 
rcashonAuthor Commented:
Thanks for the input.
0
 
twj100Commented:
hi...i'm planning to use datetime picker on my asp code but it seems like its not working...
can anyone here give me a brief tutorial on how to do it?
do i have to register some activex file or?
0
 
Cools_-Commented:
rcashon,
well solved and explained, i had exactly the same problem and guess what you saved me lot of time to solve that problem Thanks
Cools_-
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 11
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now