Solved

# Set DateTimePicker value

Posted on 2001-08-30
456 Views
Last Modified: 2012-05-04
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
Question by:rcashon
• 11
• 3
• 3
• +2
19 Comments

LVL 11

Expert Comment

ID: 6442116
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

LVL 1

Author Comment

ID: 6442210
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

LVL 11

Expert Comment

ID: 6442269
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

LVL 1

Author Comment

ID: 6444325
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

LVL 2

Expert Comment

ID: 6444416
It does seem strange but basically you have to set value=
DateDiff("d", "1/1/1900", Now) + 2 to get today's date.
0

LVL 1

Author Comment

ID: 6444418
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

LVL 1

Author Comment

ID: 6444431
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

LVL 2

Expert Comment

ID: 6444493
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

LVL 1

Author Comment

ID: 6444523
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

LVL 1

Author Comment

ID: 6444552
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

LVL 2

Accepted Solution

damienm earned 100 total points
ID: 6444918
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

LVL 1

Author Comment

ID: 6444938
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

LVL 11

Expert Comment

ID: 6444947
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

LVL 1

Author Comment

ID: 6444974
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

LVL 1

Author Comment

ID: 6444976
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

LVL 1

Author Comment

ID: 6444988
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

LVL 1

Author Comment

ID: 7326484
Thanks for the input.
0

LVL 1

Expert Comment

ID: 7632664
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

Expert Comment

ID: 9419142
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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Title # Comments Views Activity
format nvarchar field as mm/dd/yyyy 4 71
jquery to restrict certain words from input in form 11 35
Get hold of longitude and latitude in iframe string 11 46
Button to go back 3 25
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information â€¦
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interactâ€¦
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaacâ€¦
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage emâ€¦

#### 809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.