473,661 Members | 2,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

130 New Member
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">Sunda y</option>
<option value="1">Monda y</option>
<option value="2">Tuesd ay</option>
<option value="3">Wedne sday</option>
<option value="4">Thurs day</option>
<option value="5">Frida y</option>
<option value="6">Satur day</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 1594
acoder
16,027 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
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 New Member
thanks,
its all make sense now
Jan 17 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
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
3976
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 I can determine, there are 14 possible calendar variations. Year starts on Sun, Mon..... Leap year starts on Sun, Mon.. I can label these early year "types" as a number between 0 and 13.
11
3628
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 depending the the browser. Using SSI LAST_MODIFIED can return the last modified date, ISP system boot date, or many others. The only last modified date that I have been able to use with any consistancy is the SSI flastmod command.
26
2701
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 to convert a latitude coord back to an accurate date time. Then I could detect the day/hour in the viewport when the timeline is zoomed in or out, or if it is moved. I cannot use the javascript date functions because this timeline will...
12
29445
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 follows: function doDateCheckNow(source, args) { var oDate = document.getElementById(source.controltovalidate); // dd/mm/yyyy
13
3003
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
14442
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 letter. Can I use javascripting to create a webpage to allow a user to enter a letter and then click a button to find a future calendar date? I'm just not sure how much user interaction scripting allows. Does java scripting allow buttons, textfields...
44
10182
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
2507
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 unique. http://www.datejs.com/ -- -Lost Remove the extra words to reply by e-mail. Don't e-mail me. I am kidding. No I am not.
0
8428
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
8341
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
8851
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...
1
8542
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
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
6181
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
5650
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
4177
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...
2
1740
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.