473,748 Members | 2,276 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript to display current date (and back dates)

Hello all,

I've browsed through past usenet archives, but can't seem to come
across quite the javascript I'm looking for. I'm looking for a simple
javascript that will display the date as such:

May 17

So basically, just displaying the current month and the current date.
But I would also like the ability to backdate by one day, two days,
etc.. So the next date might look as such:

May 15

Which would be two days earlier than today's date, but in keeping with
the same format.

Any help on this would be greatly appreciated.
KG
Jul 23 '05 #1
3 2666
In article <d8************ *************** *****@4ax.com>, Kevin Gibbons
<kevin@<NOSPAM> kgibbons.com> enlightened us with...
Hello all,

I've browsed through past usenet archives, but can't seem to come
across quite the javascript I'm looking for. I'm looking for a simple
javascript that will display the date as such:

May 17


If you're familiar with java's SimpleDateForma t class, you might like
this author's javascript version.

http://www.mattkruse.com/javascript/date/source.html

--
--
~kaeli~
Reading while sunbathing makes you well red.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
Kevin Gibbons <kevin@ wrote:
I'm looking for a simple
javascript that will display the date as such:

May 17

I would also like the ability to backdate by one day, two days,
etc.. So the next date might look as such:

May 15
Any help on this would be greatly appreciated.


m=
["Jan","Feb","Ma r","Apr","May", "Jun","Jul","Au g","Sep","Oct", "Nov","Dec"];
n=new Date();
today=m[n.getMonth()] +" "+n.getDate ();
alert(today);

n.setDate(n.get Date()-2);
dayBeforeYester day=m[n.getMonth()]+" " +n.getDate();
alert(dayBefore Yesterday);

Something like that.
Mick
Jul 23 '05 #3
JRS: In article <d8************ *************** *****@4ax.com>, seen in
news:comp.lang. javascript, Kevin Gibbons <kevin@?.com> posted at Mon, 17
May 2004 01:12:46 :
I've browsed through past usenet archives, but can't seem to come
across quite the javascript I'm looking for. I'm looking for a simple
javascript that will display the date as such:

May 17
Did you not find the FAQ of this newsgroup?
Did you not find the FAQ of this newsgroup helpful?

So basically, just displaying the current month and the current date.
But I would also like the ability to backdate by one day, two days,
etc.. So the next date might look as such:

May 15


Not a good example; is May the name of the month, or the three-letter
abbreviation therefor? A week earlier, should that be May 5 or May 05 ?

Should the date be local-to-user, local-to-server, or GMT? I assume the
former, and that the user's computer's clock can be believed.

A = ["Jan", "Feb", "Mar", "Apr", "May", ..., "Dec"] // or "January" ..
D = new Date()
ITIS = A[D.getMonth()] + " " + D.getDate()
D.setDate(D.get Date() - 2)
TWAS = A[D.getMonth()] + " " + D.getDate()

That gives May 5 style; for May 05 use LZ(D.getDate()) with

function LZ(x) { return (x<0||x>=10?"": "0") + x }
<FAQENTRY>
IMHO, typing would be saved if LZ were in the FAQ.
</FAQENTRY>
The following can be used for the current date IF you are assured that
the first occurrence of <word> <space> <number> in String(new Date())
will ALWAYS be what you want :-

ITIS = String(new Date()).match(/(\w+ \d+)/)[1]

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
2097
by: kroger | last post by:
Hi. I am at a loss to decipher why the javascript on my web page: http://www.psych.nmsu.edu/~jkroger/lab/index.html does not display the date correctly in Firefox. Instead of "2005" for the year, it displays "105" ... however, in IE Explorer, it looks fine. Thanks for any help, Jim
19
2102
by: Stimp | last post by:
preferably one that when clicked can update three date dropdowns (day, month, year) like http://www.visitdublin.com/carhire/avis.asp Don't mind paying for the file... anyone seen something like this? -- "I hear ma train a comin' .... hear freedom comin"
5
2582
by: settyv | last post by:
Hi, Below is the Javascript function that am trying to call from asp:Button control. <script language="javascript"> function ValidateDate(fromDate,toDate) { var fromDate=new Date();
1
3846
by: xtremebass | last post by:
Hello Bytes, i have a calender program which is created by using Javascript. when i execute that program using Internet Explorer,it works properly but when i tried in Mozilla firefox it didnt worked. Dates of particular year,month not displayed in that calender grids. i have collected that coding from online free resources. Here i have attached code for your reference. please do suggest me how do i display the calender date in grids in...
0
8995
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9558
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9378
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9253
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6798
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6077
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2216
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.