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

x
?
Solved

Extract date

Posted on 2012-04-12
5
Medium Priority
?
183 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 400 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 1600 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

704 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