Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-24-2013, 08:27 AM   PM User | #1
BobbyRachel
New Coder

 
Join Date: Dec 2012
Posts: 11
Thanks: 2
Thanked 0 Times in 0 Posts
BobbyRachel is an unknown quantity at this point
How to remove time portion of date using javascript?

i have a javascript variable which holds date time value... i need only date from it...

Code:
<script type="text/javascript">
    function update(){
    var datefield = document.getElementById("myTextBox_CWPWORKLIST.DUE_DATE").value;
    alert(datefield);
    }
    </script>

here the datefield = 2013-02-21 00:00:00.0... i need datefield = 2013-02-21.. how to get this..
BobbyRachel is offline   Reply With Quote
Old 01-24-2013, 09:27 AM   PM User | #2
xhtmlchamps1
New to the CF scene

 
Join Date: Jan 2013
Location: Hyderabad
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
xhtmlchamps1 is an unknown quantity at this point
var datefield = document.getElementById("myTextBox_CWPWORKLIST.DUE_DATE").value;
var s = datefield;
var n = s.slice(0, -10);
alert(n);


This code definitely meets your requirements i think.

Thank you.
xhtmlchamps1 is offline   Reply With Quote
Users who have thanked xhtmlchamps1 for this post:
BobbyRachel (01-24-2013)
Old 01-24-2013, 09:36 AM   PM User | #3
BobbyRachel
New Coder

 
Join Date: Dec 2012
Posts: 11
Thanks: 2
Thanked 0 Times in 0 Posts
BobbyRachel is an unknown quantity at this point
here is my answer:

Code:
<script type="text/javascript">
    function update(){
    var datefield = document.getElementById("myTextBox_CWPWORKLIST.DUE_DATE").value;
    alert(datefield);
var columnname = dateFormat(datefield, "dd-mm-yy");
alert(datefield);
    }
    </script>
BobbyRachel is offline   Reply With Quote
Old 01-24-2013, 06:43 PM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,455
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by BobbyRachel View Post
here is my answer:

Code:
<script type="text/javascript">
    function update(){
    var datefield = document.getElementById("myTextBox_CWPWORKLIST.DUE_DATE").value;
    alert(datefield);
var columnname = dateFormat(datefield, "dd-mm-yy");
alert(datefield);
    }
    </script>
Your answer is incomplete - you haven't included the code for the dateFormat function you created and the part of the code that actually does what the OP asked is presumably somewhere in that function.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 01-24-2013, 09:24 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Ummm...Felgall: The "OP" here is the same person who wrote the non-answer that you commented on.

I think we have to assume he stole...err...copied...a dateFormat() function from someplace.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-24-2013, 09:37 PM   PM User | #6
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,455
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by Old Pedant View Post
I think we have to assume he stole...err...copied...a dateFormat() function from someplace.
Which will not help the next person coming here searching for an answer to the same question as there still isn't an actual complete solution to the question published.

Since none of the code here actually validates what the field contains at all the first step would be to validate that the field actually contains a date/time and to load that into an appropriate JavaScript variable using new Date(). Then you can easily extract just the date portion using the appropriate methods.

Neither version of the code the OP posted would work if the person entered "noon yesterday" as their date and time even though the code they have would allow that input.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 01-24-2013, 09:42 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
LOL! Well, crud. And here I wanted to be able to enter "my next birthday" and have JavaScript figure it out! What a truly worthless language. <grin/>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-25-2013, 01:09 AM   PM User | #8
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,455
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by Old Pedant View Post
LOL! Well, crud. And here I wanted to be able to enter "my next birthday" and have JavaScript figure it out!
There's nothing in the OP's code to prevent you entering that and they claimed that everything now works so presumably the dateFormat function knows when your next birthday is.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 01-25-2013, 01:31 AM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
LMAO! Touchė. I really and truly laughed out loud, not just grinned, when I read that!

Best laugh I've had all week except when my 2.5 year old granddaughter said "My cup disappeared." (You had to be there. It was mainly the shock of the big word, but the cup was right behind her.)
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:35 PM.


Advertisement
Log in to turn off these ads.