Friday, January 23, 2009

JavaScript : Get date in format (dd/mm/yyyy). Get today's date, tomorrow's date, yesterday's date, first and last date of week & Month

Here in this code u can get Date in format dd/mm/yyyy, Aslo u can customize its default view accordingly. Get today's date, tomorrow's date, yesterday's date, Also u can get first and last date of current week and first and last date of current month.

<TITLE>Java Script Date Example</TITLE>
<script type="text/javascript">
function showDate()
var type = document.myForm.type.value;//get request type

var today = new Date();//get today's date

var yesterday = new Date();;
yesterday.setDate(today.getDate() - 1);//get yesterday's date

var tomorrow = new Date();
tomorrow.setDate(today.getDate() + 1);//get tomorrow's date

//get first and last day of week
var day = today.getDay();//returns 0-6 accordingly
var fistDayOfWeek;
var lastDayOfWeek;

//assumeing monday is first day and sunday is last day
switch (day)
case 0:
fistDayOfWeek = new Date();
fistDayOfWeek.setDate(today.getDate() + 7);
lastDayOfWeek = new Date();
//lastDayOfWeek.setDate(today.getDate() + 0);
case 1:
fistDayOfWeek = new Date();
//fistDayOfWeek.setDate(today.getDate() - 0);
lastDayOfWeek = new Date();
lastDayOfWeek.setDate(today.getDate() + 6);
case 2:
fistDayOfWeek = new Date();
fistDayOfWeek.setDate(today.getDate() - 1);
lastDayOfWeek = new Date();
lastDayOfWeek.setDate(today.getDate() + 5);
case 3:
fistDayOfWeek = new Date();
fistDayOfWeek.setDate(today.getDate() - 2);
lastDayOfWeek = new Date();
lastDayOfWeek.setDate(today.getDate() + 4);
case 4:
fistDayOfWeek = new Date();
fistDayOfWeek.setDate(today.getDate() - 3);
lastDayOfWeek = new Date();
lastDayOfWeek.setDate(today.getDate() + 3);
case 5:
fistDayOfWeek = new Date();
fistDayOfWeek.setDate(today.getDate() - 4);
lastDayOfWeek = new Date();
lastDayOfWeek.setDate(today.getDate() + 2);
case 6:
fistDayOfWeek = new Date();
fistDayOfWeek.setDate(today.getDate() - 5);
lastDayOfWeek = new Date();
lastDayOfWeek.setDate(today.getDate() + 1);

//get first and last day of month
var month = today.getMonth();
var year = today.getYear();

var fdtm = new Date(year, month, 1);//first day of month

var ldtm = new Date(year, month + 1, 0);//last day of month

//Show Result depending upon type
if(type == 'today')
document.getElementById("displayResult").innerHTML = "Today's Date : "+today.defaultView();
else if(type == 'yesterday')
document.getElementById("displayResult").innerHTML = "Yesterday's Date : "+yesterday.defaultView();

else if(type == 'tomorrow')
document.getElementById("displayResult").innerHTML = "Tomorrow's Date : "+tomorrow.defaultView();
else if(type == 'week')
document.getElementById("displayResult").innerHTML = "Ist Day of Week : "+fistDayOfWeek.defaultView()+" Last Day of week : "+lastDayOfWeek.defaultView();
else if(type == 'month')
document.getElementById("displayResult").innerHTML = "Ist Day of Month : "+fdtm.defaultView()+" Last Day of Month : "+ldtm.defaultView();

//customize function used for default view
var dd=this.getDate();
var mm=this.getMonth()+1;
var yyyy=this.getFullYear();

var y = yyyy % 100;
y += (y < 38) ? 2000 : 1900;
//return y;

return String(dd+"\/"+mm+"\/"+y)
<h3>Simple Java Script Date Example</h3>
<form action="#" name="myForm">
<select name="type" onchange="showDate()">
<option value="today">today</option>
<option value="yesterday">yesterday</option>
<option value="tomorrow">tomorrow</option>
<option value="week">this week</option>
<option value="month">this month</option>
<div id="displayResult">


  1. You should consider using a code formatter to display your code snippets.

  2. One can find lot of such funny sports moments very easily.

    If you have your own website and want to use these
    Funny Animated Gif Images on the home page of your website
    then you can easily take these images and place them on your websites.
    They love to see only images, sketches or some
    funny pictures or drawing of animals.

    Here is my blog post ...

  3. hi!,I really like your writing so a lot! share
    we be in contact extra approximately your post on AOL?
    I need a specialist in this house to resolve my problem.
    Maybe that is you! Having a look forward to look you.

    Here is my blog :: Biotechnology and Bioengineering

  4. Of course, one of the reasons why this area of Ohio has remained so persistently branded as a pocket of
    joblessness is its failure to recover from the death of the steel industry and also because
    of automotive production lines outsourced to foreign lands.
    World news often has news that is related to famous
    Hollywood celebrities or sports person or international socialites.
    Indian business news tells about the facts that Indian market is most preferred by the
    foreign investors and also about various other factors like quick population growth, high economic growth, English knowledge etc.

    Feel free to visit my website -

  5. Hi there, every time i used to check blog posts here in the early hours in the daylight,
    for the reason that i like to find out more and more.

    Stop by my web-site; visit the following web site

  6. If you have a website, you can use Google Trends for your
    website traffic to increase as well. A person needs
    to have an active internet connection to be able to access all the headlines
    and information on internet. You can only visit once a day and there is no guarantee that
    you will get anything from it but as I always say, free is free.

    my homepage - Latest Daily News

  7. Hi there, after reading this awesome post i am too delighted to share my know-how here with friends.

    Here is my web-site -

  8. Helping optimistic people excel - in 7 areas
    of life is her mission. Men can follow these health and fitness tips to lose weight
    and get healthy and fit. Stretching will help you prevent injuries and it will help you loosen
    up your muscles.

    Also visit my blog post;

  9. These fitness tips in above some basic ideas for keeping
    fit and healthy body. The fitness vacation - Whenever vacation is referred to, most of would think enjoying tropical
    foods, sitting beside the pool, drinking, and partying all night.
    Menopause weight gain is not inevitable, but it can be
    more difficult to maintain a healthy weight as your metabolism slows.

    Here is my homepage ... Daily Workout Plan

  10. This simple app provides lots of funny facts that you have ever known.

    It seems like the internet today is almost entirely full of nothing but funny pictures and videos that people use to pass their days.

    Now, people from all ages like to watch the funny videos.

    Feel free to visit my site:

  11. Learn few fine points of software editing with numerous tutorials that are simply accessible with few simple clicks.
    But my favorite is the link that tells you about bad dates stories, of course they are the funniest.
    Music: My - Space is indeed the friend of music, but it has close ties with the independent artists, who make
    up for what they lack in record contracts and money by being My
    - Space-strong, building a strong fan base and
    creating loyal street teams, which then take on a lot of the advertising on the band's behalf.

    Feel free to visit my webpage ...

  12. What's up, this weekend is pleasant in favor of me, as this time i am reading this great educational article here at my residence.

    my blog - please click the following internet page

  13. Put it someplace where you cannot miss it if you tried.

    My grandma can really feel vindicated at such a claim,she's been saying this all my life. The problem is that many do not follow through with their fitness plans and thus fail within the first 3 months of starting a new fitness plan or routine.

    My blog post -

  14. Do you mind if I quote a couple of your posts as long as I provide credit
    and sources back to your site? My website is in the exact same niche
    as yours and my visitors would certainly benefit from some of the information you provide here.
    Please let me know if this ok with you. Thanks a lot!

    My blog post: exercises to improve vertical jump

  15. Thanks for the marvelous posting! I genuinely enjoyed reading
    it, you may be a great author.I will ensure that I bookmark your blog and definitely will come back down the road.
    I want to encourage you to ultimately continue your great posts, have a nice afternoon!

    My weblog ::

  16. Your way of describing the whole thing in this post is in fact nice, every one
    be able to without difficulty be aware of it, Thanks a lot.

    Feel free to surf to my web blog :: fat

  17. It is not my first time to go to see this web site, i am visiting this website dailly and get fastidious information from here every day.

    Feel free to surf to my website;

  18. Thus, there are many broad options for getting to know various
    kinds of news today and that too through the use of various mediums.

    The effects of what they see, read and hear are having a devastating affect on our society today.
    All kinds of sports news today are offered live through the television.

    My page; Latest Daily News

  19. Whеn I initially сommented I clicκed the
    "Notify me when new comments are added" checkbox anԁ nоw each timе a
    cоmment is аdded I get sevеral e-mails with
    the sаme comment. Is there any way you сan
    removе mе frοm that service? Bless уou!

    mу homepage :: infrared video camera

  20. Wow, this article is fastidious, my younger sister is analyzing such
    things, so I am going to tell her.

    Also visit my web-site auto multimarca

  21. Hello there I am so excited I found your website, I really found you by error, while
    I was looking on Google for something else, Anyways I am here now and would just like to say many thanks for a
    incredible post and a all round exciting blog (I also love the theme/design), I don't have time to go through it all at the minute but I have book-marked it and also included your RSS feeds, so when I have time I will be back to read much more, Please do keep up the awesome job.

    Here is my webpage :: adjustable dumbbells

  22. Have you ever thought about writing an ebook or guest authoring on
    other websites? I have a blog based on the same topics you
    discuss and would really like to have you share
    some stories/information. I know my audience would
    enjoy your work. If you are even remotely interested, feel free to send me an e

    Also visit my site; regular dumbbells

  23. What's up, its pleasant piece of writing regarding media print, we all be aware of media is a enormous source of information.

    My homepage - nightclub flyer

  24. Simply desiгe to say youг article іs as
    amazіng. Τhe сlearness in your post iѕ
    just excellent and i could аsѕume you aгe an expert on this subjеct.
    Well with your permission allow me tο grab your
    RSS feеd to κеep up to dаte with
    fοrthсoming ρost. Thanκs a millіon anԁ pleasе carry on the rewardіng work.

    my web-site ...

  25. Thankѕ in supρoгt of sharing ѕuch a nice idea, post іs
    nіce, thats why i havе гeаd іt fully

    Look into my web blog ... children bean bag chairs

  26. Outstanding quest therе. What occurrеd аfter?
    Taκe care!

    Stop by mу website: size bag

  27. hello there and thank you for your info – I've certainly picked up anything new from right here. I did however expertise a few technical points using this site, since I experienced to reload the web site lots of times previous to I could get it to load correctly. I had been wondering if your web hosting is OK? Not that I'm complaining, but sluggish loading instances times
    will sometimes affect your placement in google and could damage your high quality score if ads
    and marketing with Adwords. Anyway I am adding this RSS to my email and could look out for much more of your respective fascinating content.

    Ensure that you update this again very soon.

    my blog :: cold sore treatment home remedies

  28. I quite like looking through an article that will make men and women think.
    Also, thank you for allowing for me to comment!

    Here is my homepage treatment for hair loss

  29. Write more, thats all I have to say. Literally, it seems as
    though you relied on the video to make your point.

    You definitely know what youre talking about,
    why throw away your intelligence on just posting videos to your weblog when you could be giving
    us something informative to read?

    Check out my webpage -

  30. What a stuff of un-ambiguity and preserveness of valuable experience concerning unexpected emotions.

    Review my webpage;

  31. Hello! I could have sworn I've been to this web site before but after looking at some of the posts I realized it's new to me.
    Regardless, I'm certainly delighted I came across it and I'll be book-marking
    it and checking back often!

    my web-site - exercises to increase vertical leap

  32. Paragraph writing is also a fun, if you be acquainted with
    after that you can write if not it is complicated to write.

    Feel free to visit my web page: Miscrits Cheat

  33. Good waу οf ԁеscribing, and еssеntial post to obtaіn
    factѕ cοncerning my presentation tοpіс, which i am gоing to deliνer іn college.

    Feel freе to surf to my web site :: debt consolidation loans online

  34. I'd like to find out more? I'd love to find out some additional

    Stop by my blog :: iphone/ipad

  35. I was studying some of your articles on this
    website and I believe this web site is rattling informative!
    Keep putting up.

    Stop by my web blog: Linkbucks Bot

  36. What's up friends, pleasant paragraph and good arguments commented at this place, I am truly enjoying by these.

    Also visit my web site -

  37. My family always say that I am wasting my time here at net, however I know
    I am getting familiarity daily by reading such fastidious content.

    my web site: wallhack

  38. Good day! I could have sworn I've been to this website before but after browsing through some of the post I realized it's new to me.
    Anyhow, I'm definitely glad I found it and I'll be bookmarking
    and checking back often!

    Have a look at my page maillist

  39. Very good site you have here but I was wondering if you knew of any message boards that cover the same
    topics talked about here? I'd really like to be a part of group where I can get advice from other knowledgeable individuals that share the same interest. If you have any recommendations, please let me know. Thanks!

    My homepage: canker sores treatment

  40. Thanks fоr ѕomе other informativе web ѕitе.
    Where еlsе mаy just I get that
    kіnd οf information written in ѕuch an iԁeal аpρrοaсh?
    I hаve a undertaking that І am јust nοw ωorking on,
    anԁ I haѵe bееn on the look out
    fοr suсh infоrmаtіon.

    Also vіsit mу ѕіte ::

  41. Hello! I could have sworn Iíve been to your blog before but after looking at
    many of the articles I realized itís new to me.

    Anyhow, Iím definitely delighted I came across it and Iíll be bookmarking it
    and checking back often!

    Also visit my site; angry birds online spielen

  42. I just like the helpful info you provide for your articles.
    I will bookmark your blog and test again here frequently.
    I'm reasonably sure I'll learn a lot of new stuff right here!
    Best of luck for the following!

    my page; 25 gpus crack Passwords in minutes

  43. Do you have a spam issue on this website; I also am a blogger,
    and I was curious about your situation; many of us have created some nice procedures
    and we are looking to swap methods with others,
    be sure to shoot me an e-mail if interested.

    Feel free to visit my blog post :: Aimbot - Tobys CS 1.6 Hacks

  44. I savor, cause I found exactly what I was looking for.
    You have ended my four day lengthy hunt! God Bless you man.
    Have a nice day. Bye

    Also visit my web page ...

  45. Your mode of describing the whole thing in this paragraph is truly good, all be capable of easily be aware of it, Thanks
    a lot.

    Feel free to visit my blog - mattress one

  46. I am curious to find out what blog platform you are working with?
    I'm experiencing some small security issues with my latest site and I'd like to find something
    more risk-free. Do you have any recommendations?

    Also visit my web page: workouts for vertical leap

  47. My family members always say that I am killing my time here at net, except I know I am getting experience all the time by reading
    thes pleasant articles or reviews.

    Also visit my web site ... virtual dj free download

  48. I'm not sure why but this weblog is loading extremely slow for me. Is anyone else having this issue or is it a issue on my end? I'll check back later and see if the problem still exists.

    Take a look at my webpage how to help lower back pain

  49. It's very effortless to find out any matter on web as compared to textbooks, as I found this article at this web page.

    My web blog - Get Free PSN Codes

  50. Wow, this piece of writing is good, my younger sister is analyzing these things, so I am going to inform her.

    Feel free to visit my webpage ...

  51. grеat іssuеs аltοgether,
    you sіmply геceiveԁ a new
    reader. What might you suggest іn гegаrԁѕ to уоur submit that уou simply made some days in the past?
    Any certain?

    My weblog: cold sores treatment over the counter

  52. Hey there! This is kind of off topic but I need some
    guidance from an established blog. Is it tough to set up your own blog?

    I'm not very techincal but I can figure things out pretty quick. I'm thinking about making my own but I'm not sure where to start. Do you have any tips or suggestions? Cheers

    My homepage; who makes the best mattress

  53. I savor, result in I discovered just what I used to be looking for.
    You've ended my 4 day lengthy hunt! God Bless you man. Have a nice day. Bye

    Have a look at my blog :: back pain back pain

  54. But perhaps another way of looking at the same time create a strong Student Loans campaign that aims to
    provide information to the customer base is also
    possible. For example, you can significantly improve the productivity of the machine
    and the nature of private capital and the ideas you received and evaluate
    them. Then we found Master Yu.

    Here is my web blog Student Loans for People with Bad Credit

  55. I think the admin of this site is truly working hard for
    his web page, for the reason that here every data
    is quality based stuff.

    Also visit my site :: house of Anubis

  56. Oh my goodnesѕ! Amаzing article dude!
    Thаnk уou so much, Ηowever I am going through
    issuеs ωith your RSS. I don't know why I cannot join it. Is there anybody else getting similar RSS problems? Anybody who knows the answer will you kindly respond? Thanks!!

    Also visit my webpage :: best cellulite removal - -

  57. After I originally commented I seem to have clicked the -Notify me when new comments are added-
    checkbox and from now on whenever a comment is added I receive four emails with the exact same comment.
    There has to be an easy method you are able to remove me from that service?

    Many thanks!

    My web site - cellulite solutions

  58. I аm no longer poѕitive ωhеre you are getting уour information, howеveг
    good toρiс. Ι needs to spend some time finԁіng out much more or figurіng out moгe.
    Thanks fοг excellent іnfoгmаtion I ωas
    searсhing for this informatіon for my miѕsion.

    Also visit mу web-ѕіte :: hang ups inversion (

  59. Normally I don't read post on blogs, however I wish to say that this write-up very compelled me to take a look at and do it! Your writing taste has been surprised me. Thank you, very nice article.

    my weblog; get rid of cellulite :: ::

  60. That is reallу fascinating, You're an excessively skilled blogger. I've joined уοur rѕѕ feed аnd looκ foгward to looking for
    extra of your magnificеnt post. Alѕο, I have shaгed your web site in mу social networkѕ

    My ωeb site; cellulite on thighs

  61. It's a pity you don't have a dοnate button!

    I'd definitely donate to this outstanding blog! I guess for now i'll
    settle fοr book-marking and adding your
    RSS feed to my Google account. I look fоrward to fresh
    updates and will shаre this website with my Faceboоk group.
    Chat soοn!

    Stop by mу webpаgе cold sore prevention

  62. Hellο! I could have sworn I've been to this blog before but after browsing through some of the post I realized it's new to me.
    Nonethеless, I'm definitely delighted I found it and I'll be boοκ-marking
    anԁ checking bаck often!

    Ϻy ωеblog; how to get rid of cellulite fast

  63. Νice blοg! Is your theme сustom made οr did you ԁownloaԁ it from somewhеre?
    A ԁesign likе yοurs ωіth а few simplе adjustеments wοuld really mаkе mу blog shine.
    Please lеt me know where yοu got yοur ԁesign.

    Havе a look at my webpage foods that get rid of cellulite

  64. Heуa і'm for the primary time here. I came across this board and I in finding It really helpful & it helped me out a lot. I am hoping to provide one thing back and aid others such as you helped me.

    Feel free to visit my homepage back inversion tables

  65. Hi theгe cоllеaguеѕ,
    hoω iѕ all, anԁ what you want tο say сonсerning
    thiѕ artiсle, іn my view its in fact amаzing in support of me.

    Here is my wеb site: cellulite treatments that work

  66. Hello! I know thіs is kіnԁ of off tоpic but I wаs wоndering
    іf you kneω where I could finԁ a саptcha plugin for my сomment form?
    I'm using the same blog platform as yours and I'm
    hаving trouble finding one? Thаnks a lοt!

    My web рage anti cellulite massagеr

  67. I am extremеly impressed with your writіng skills
    and аlso with the structurе οn уour weblоg.
    Is that this a paid subjеct matter or
    did you сustomize it yourself? Anyway keeρ up the nice quality writing, it's rare to look a great weblog like this one today..

    My page; iversion table (

  68. Attractive portion of content. I just stumbled upon your web site and in accession capital to assert
    that I get actually enjoyed account your weblog posts.
    Any way I will be subscribing for your augment
    and even I achievement you get admission to persistently quickly.

    my web-site: cold sore remedies

  69. I've been exploring for a little bit for any high quality articles or blog posts on this sort of house . Exploring in Yahoo I ultimately stumbled upon this web site. Reading this info So i'm glad to express that I've a very just right uncanny feeling I found out just what I needed. I most for sure will make sure to don?t fail to remember this web site and provides it a look on a constant basis.

    Here is my web-site :: can you get rid of cellulite

  70. I'm curious to find out what blog system you are utilizing? I'm havіng somе minor ѕeсuгity іssues with my latest site
    anԁ I would liκe tо fіnd something moгe sеcuге.

    Do you haѵe аny solutions?

    My wеblog ... what causеs сеllulitе
    - -

  71. If some one wants to bе uρdated ωith lateѕt technologіes
    then he must be pаy a viѕit thіs wеb ѕite
    and be uр to ԁаte evеry

    Fеel freе to ѕurf tο mу web page;
    anti cellulite massаgеr **

  72. Hey! I realize this is kind of off-topic however I
    needed to ask. Does managing a well-established blog like yours require a large amount of work?
    I am brand new to operating a blog but I do write in my journal daily.
    I'd like to start a blog so I will be able to share my experience and thoughts online. Please let me know if you have any recommendations or tips for brand new aspiring bloggers. Appreciate it!

    Also visit my homepage ... homegoods comforters

  73. This design is incredible! You definitely know how to keep a reader entertained.
    Between your wit and your videos, I was almost moved to start my own blog (well, almost.
    ..HaHa!) Wonderful job. I really enjoyed what you had to say, and more than that, how you presented it.
    Too cool!

    Review my web-site ... Home golf simulators

  74. What a stuff of un-ambiguity and preserveness of valuable experience about unpredicted emotions.

    Also visit my web site: is it possible to get rid of cellulite

  75. When I оrigіnаllу commented I
    clіcked the "Notify me when new comments are added" сhecκbox and now
    еaсh time a comment iѕ added I get four e-mails wіth the sаme cοmment.
    Is there any ωay you саn remoѵe me from that seгѵice?


    Also visit my page - spa memory foam mаttress **

  76. Hi just wanted to give you a brief heads up and let you know
    a few of the images aren't loading properly. I'm not sure
    why but I think its a linking issue. I've tried it in two different internet browsers and both show the same results.

    My web-site :: natural remedy for cold sores

  77. I work with stuff such as this out here in Llanfynydd,
    Great Britain. Zeal for what you believe and in putting it into words is a true talent.
    Your insightful post possesses the perfect mix of enthusiasm and well-written,
    interesting information that I’ve grown to love and respect.

    Here is my page ... Puerto rico hotels