Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Entering a default date into a form

Posted on 1999-06-28
13
Medium Priority
?
188 Views
Last Modified: 2013-12-25
I have an input form, designed in FP 98, and one of the fields is a date field.  The form is getting processed by an ASP page.  I want to have the date field with a default value of the current day's date.  The platform is NT SERVER and I want to us VBSCRIPT.  (Yes, this is a site for an intranet, so VBSCRIPT is what I mean - all browsers are IE 4.0)

Any suggestions?  I would like the date formatted as mm/dd/yy

Thanks
Brett
0
Comment
Question by:Brett081597
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +3
13 Comments
 

Expert Comment

by:jasonbrown
ID: 1863563
use the window_onload event:

Sub window_onload
   datefield = Date()
   ...
End Sub

0
 
LVL 18

Expert Comment

by:mgfranz
ID: 1863564
Here is the entire file, copy this and save it as date.asp;

<%@ language="vbscript" %>
<html>
<head>
</head>

<body>
<%=date() %>

</body>
</html>
0
 
LVL 5

Expert Comment

by:mayhew
ID: 1863565
Assuming you want a text field to have that default value:


<INPUT TYPE="TEXT" NAME="DateField" VALUE="<%=date() %>">

0
Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

 
LVL 1

Accepted Solution

by:
mjpieters earned 300 total points
ID: 1863566
Hmmm, so you want a client side date put into the field.

VBScript's Date handling is a bit more cumbersome then Javascript's, but here goes:

<script language="VBScript">
    document.write "<INPUT TYPE=text NAME=PublishDate VALUE="""
    document.write Date()
    document.write """ SIZE=10>"
</script>

This will display a text input box that contains the current date, formatted according the locale of the machine the browser is running on. On my machine (wich has the Dutch locale), it displays the date as 26/06/99.

If this format is not what you are looking for, you will have to tweak the string using the Day, Month, MonthName
Weekday, WeekdayName and Year methods. Something like:

<script language="VBScript">
    Dim sDate, dDate

    dDate = Date()

    If Month(dDate) < 10 Then
        sDate = "0" & Month(dDate)
    Else
        sDate = Month(dDate)
    End If

    sDate = sDate & "/"

    If Day(dDate) < 10 Then
        sDate = sDate & "0" & Day(dDate)
    Else
        sDate = sDate & Day(dDate)
    End If

    sDate = sDate & "/" & Year(dDate)

    document.write "<INPUT TYPE=text NAME=PublishDate VALUE="""
    document.write sDate
    document.write """ SIZE=10>"
</script>

Above script will format dates according to the mm/dd/yyyy format.

0
 
LVL 1

Expert Comment

by:mjpieters
ID: 1863567
Oh, just saw the format you would like =)

If the locale of your machines probably already will give you mm/dd/yy formatted dates. If not, the following VBScript code will put such a string into the variable sDate:

    Dim sDate, dDate

    dDate = Date()

    If Month(dDate) < 10 Then
        sDate = "0" & Month(dDate)
    Else
        sDate = Month(dDate)
    End If

    sDate = sDate & "/"

    If Day(dDate) < 10 Then
        sDate = sDate & "0" & Day(dDate)
    Else
        sDate = sDate & Day(dDate)
    End If

    sDate = sDate & "/" & Right(Year(dDate), 2)


0
 
LVL 10

Expert Comment

by:MasseyM
ID: 1863568
Why not use
<%
TheDate = FormatDateTime(Now(), 1)
Response.Write TheDate
%>

this will print mm/dd/yy

0
 
LVL 18

Expert Comment

by:mgfranz
ID: 1863569
Mike,

Don't you mean this;

<%
      TheDate = FormatDateTime(Date(), 1)
      Response.Write TheDate
%>

Mark
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 1863570
Mike,

Don't you mean this;

<%
      TheDate = FormatDateTime(Date(), 1)
      Response.Write TheDate
%>

Mark
0
 
LVL 10

Expert Comment

by:MasseyM
ID: 1863571
Yes. Sorry...

Used Now() rather than Date()
0
 

Author Comment

by:Brett081597
ID: 1863572
I think your answer will work, but another answer I got worked and was much simplier.  You get the points because you answered and not commented.  Thanks for you help.
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 1863573
Hey Brett, if that is the case why didn't you just reject the answer?  Not that is was an incorrect answer, but if I can squeeze 19 lines and 3 loop statements into 1 line...

Anyway, glad you got it fixed...
0
 
LVL 1

Expert Comment

by:mjpieters
ID: 1863574
Some comments:

- The question was how to do it client side.
- Now() gets you both date and time, Date() only gives the current date.
- FormatDateTime() uses the current system locale. I believe that IIS 5 will let you set the locale of the ASP app independent of the machine locale. Problem is, that if you cannot influence the locale of the machine (because it is running at an ISP, for example), you cannot rely on FormatDateTime() to always return the right format.


0
 
LVL 18

Expert Comment

by:mgfranz
ID: 1863575
Hmmm... I don't see anywhere in the original post where it specifies that it must be client side.  

As for FormatDateTime(), read the function rules.  http://msdn.microsoft.com/scripting/default.htm?/scripting/VBScript/doc/vsfctFormatDateTime.htm  Setting the named format to 1 will return the long date.  

If my ISP cannot set the server time correctly, I will be finding another ISP...
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

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

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

Join & Ask a Question