Solved

Extract date

Posted on 2012-04-12
5
171 Views
Last Modified: 2012-04-17
I'm trying to use the code below to extract the date with out the time.
The result I get is 1st of April  with a time stamp still.

<script type="text/javascript">
 <!--
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
curr_month++;
var curr_year = d.getFullYear();
document.getElementsByName('SubscriberDate')[0].value = ("0" +
curr_month).slice(-2) + "/" + curr_year;//-->
</script>

Open in new window

0
Comment
Question by:Isaac
5 Comments
 
LVL 7

Expert Comment

by:dimmergeek
ID: 37839934
Good afternoon.

This code displays 04/2012 in IE, Chrome and FF.

    <script type="text/javascript">
        var d = new Date();
        var m = d.getMonth() + 1;
        var y = d.getFullYear();
        if (m < 10) {
            document.write('0');
        }
        document.write(m + '/' + y);
    </script>

I ran your code and got an error at the .slice.  All I saw on my screen was '04'.
0
 
LVL 5

Author Comment

by:Isaac
ID: 37839972
How do I get it to display the full date?

Thanks!
0
 
LVL 7

Assisted Solution

by:dimmergeek
dimmergeek earned 100 total points
ID: 37840083
<script type="text/javascript">
        var d = new Date();
        var m = d.getMonth() + 1;
        var dt = d.getDay();
        var y = d.getFullYear();
        if (m < 10) {
            document.write('0');
        }
        document.write(m + '/');
        if (dt < 10)
        {
            document.write('0');
        }
        document.write(dt + '/' + y);

Full date with zeros ahead of month and day numbers when they are less than 10.
0
 
LVL 20

Accepted Solution

by:
Proculopsis earned 400 total points
ID: 37841330
Try this jsfiddle:

var date = new Date();

$("#SubscriberDate").text(date.toString("MM/YYYY"));

Open in new window

0
 
LVL 41

Expert Comment

by:HonorGod
ID: 37842195
If you want to learn more about dates in Javascript, you might be interested in this article:

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_484-Can-I-have-a-date.html
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now