473,395 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

date / time object in javascript, Qustion about day of the week

130 100+
hello all

i am breaking my head over this and there isnt any good solution that i have saw til now, my problam is that i want to tell the date of a sertin day what was choosen

[HTML]<select id="7_day" name ="7days">
<option value="0">Sunday</option>
<option value="1">Monday</option>
<option value="2">Tuesday</option>
<option value="3">Wednesday</option>
<option value="4">Thursday</option>
<option value="5">Friday</option>
<option value="6">Saturday</option>
</selectt>[/HTML]
when the user choose one of this days i will be able to get the date of all the last 5 sunday's for example

the problam i am getting is when trying to minus 7 out of the:

Expand|Select|Wrap|Line Numbers
  1. today = new Date();
  2. alert(today.getDate()-7 )
this is fine as long as we are not at the age.
Expand|Select|Wrap|Line Numbers
  1. alert (today.getDate()-28)
will bring back minus
i dont want to calculate it as intgers i want to calculate it as dates is it possible?? in php i would use mktime but js dont have it :(
somthing like that :
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $date= date("Y-m-d");
  3. $day = explode("-",$date);
  4. $lastWeek= strftime("%Y-%m-%d",(mktime(0,0,0,$day[1],$day[2]-7,$day[0])));
  5. ?>
any idea??
Jan 17 '08 #1
5 1585
acoder
16,027 Expert Mod 8TB
Use the setDate() method:
Expand|Select|Wrap|Line Numbers
  1. var today = new Date();
  2. var newDate = new Date();
  3. newDate.setDate(today.getDate()-7);
Jan 17 '08 #2
Amzul
130 100+
that return seconds since epoch, (progress :))
how can i convert it to string like this yyyy-mm-dd
Jan 17 '08 #3
acoder
16,027 Expert Mod 8TB
that return seconds since epoch, (progress :))
how can i convert it to string like this yyyy-mm-dd
Just output a string using the get*** methods:
Expand|Select|Wrap|Line Numbers
  1. alert(newDate.getFullYear() + "-" + (newDate.getMonth()+1) + "-" + newDate.getDate());
Jan 17 '08 #4
Amzul
130 100+
thanks,
its all make sense now
Jan 17 '08 #5
acoder
16,027 Expert Mod 8TB
You're welcome. Glad it helped.
Jan 17 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Mick White | last post by:
According to the Safari browser the world began on "Fri Dec 13 1901 15:45:52 GMT-0500", but I need to be able to get around this limitation. I am interested in dates from 1500 to 1901, as far as...
11
by: Dennis Marks | last post by:
There seems to be a major program with the automatic display of the last modified date. Using the javascript "document.lastModified" sometimes returns the correct date and sometimes 1 Jan 1970...
26
by: jshanman | last post by:
I am writing a timeline that uses Google Maps. I have a function that converts a date time to latitude coords. This function is used to draw the markers on the timeline. I need a reverse function...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
13
by: ahjiang | last post by:
Hi all, Need some help here. How do i create a javascript date object with the format (yyyy:mm:dd hh:mm:ss) do i need to parse it to achieve that? appreciate any inputs
6
by: rohayre | last post by:
Im a long time java developer and actually have never done anything with java scripting. I'd like to write a short simple script for calculating a date in the future based on today's date and a...
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
34
by: -Lost | last post by:
I'm REALLY liking this so far. And for those who welcome something a little less cryptic than what the resident date guru offers, here's a chance to try something fairly elegant and definitely...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.