Solved

Extract date

Posted on 2012-04-12
5
175 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
[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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

752 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