473,396 Members | 2,158 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,396 software developers and data experts.

Date function

trz
Hi Im new to this I was looking for javascript that will display the
following:
If the current day is less than the 15th that it would display the
current Month and the 30th. i.e.
This offer is good until November 15th or This offer is good until
November 30th .
am I clear?

trz

Oct 21 '06 #1
5 1181
trz wrote:
Hi Im new to this I was looking for javascript that will display the
following:
If the current day is less than the 15th that it would display the
current Month and the 30th. i.e.
This offer is good until November 15th or This offer is good until
November 30th .
am I clear?

trz
Hi trz,

In your copy of "javascript: The Definitive Guide" by Flanagan or other
JavaScript reference book, look up Date.getDate() and Date.getMonth()
in the Core JavaScript Reference section. Combine those with a few if
statements and you should be there.

Peter

Oct 21 '06 #2
trz
Thanks, Peter I'll check it out.
Peter Michaux wrote:
trz wrote:
Hi Im new to this I was looking for javascript that will display the
following:
If the current day is less than the 15th that it would display the
current Month and the 30th. i.e.
This offer is good until November 15th or This offer is good until
November 30th .
am I clear?

trz

Hi trz,

In your copy of "javascript: The Definitive Guide" by Flanagan or other
JavaScript reference book, look up Date.getDate() and Date.getMonth()
in the Core JavaScript Reference section. Combine those with a few if
statements and you should be there.

Peter
Oct 21 '06 #3
In message <11**********************@f16g2000cwb.googlegroups .com>, Sat,
21 Oct 2006 10:10:52, trz <te****@gmail.comwrites
>Hi Im new to this I was looking for javascript that will display the
following:
If the current day is less than the 15th that it would display the
current Month and the 30th. i.e.
This offer is good until November 15th or This offer is good until
November 30th .
am I clear?
Inadequately. Firstly, February exists. Secondly, it might be the
31st.

The following should, on the 1st..14th, give the 15th, otherwise the
last, of the current month.

with (D = new Date())
getDate()<15 ? setDate(15) : setMonth(getMonth()+1, 0)

But your specification is inadequate to indicate what you really want,
and suggests that you have not given enough thought to the problem
itself before seeking a solution.

For January to April inclusive, post a critical table of the ISO-8601
date/times and the desired results, such as

2004-01-01.0
2004-01-15
2004-01-15.0
2004-01-31
....

If this is a commercial application, you may need to deal with the
user's local date being different to the date at the Company. Consider
a New Yorker visiting New Zealand and wanting to deal with Hawaii.

If this is coursework, admit it.

It's a good idea to read the newsgroup and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Oct 21 '06 #4
J R Stockton wrote:
In message <11**********************@f16g2000cwb.googlegroups .com>, Sat,
21 Oct 2006 10:10:52, trz <te****@gmail.comwrites
Hi Im new to this I was looking for javascript that will display the
following:
If the current day is less than the 15th that it would display the
current Month and the 30th. i.e.
This offer is good until November 15th or This offer is good until
November 30th .
am I clear?

Inadequately. Firstly, February exists. Secondly, it might be the
31st.

The following should, on the 1st..14th, give the 15th, otherwise the
last, of the current month.

with (D = new Date())
getDate()<15 ? setDate(15) : setMonth(getMonth()+1, 0)
It might be confusing to suggest using with() to a beginner. It seems
like the use of with() is discouraged in many places.

Oct 21 '06 #5
In article <11**********************@f16g2000cwb.googlegroups .com>,
Peter Michaux <pe**********@gmail.comwrites
>J R Stockton wrote:
>In message <11**********************@f16g2000cwb.googlegroups .com>, Sat,
21 Oct 2006 10:10:52, trz <te****@gmail.comwrites
>Hi Im new to this I was looking for javascript that will display the
following:
If the current day is less than the 15th that it would display the
current Month and the 30th. i.e.
This offer is good until November 15th or This offer is good until
November 30th .
am I clear?

Inadequately. Firstly, February exists. Secondly, it might be the
31st.

The following should, on the 1st..14th, give the 15th, otherwise the
last, of the current month.

with (D = new Date())
getDate()<15 ? setDate(15) : setMonth(getMonth()+1, 0)

It might be confusing to suggest using with() to a beginner. It seems
like the use of with() is discouraged in many places.
Alternatively, add a note that it's an example of the safe use of
'with'. Nothing will go wrong even if Date objects, or all objects, have
been given extra properties with weird names.

John
--
John Harris
Oct 23 '06 #6

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

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
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...
6
by: Luvin lunch | last post by:
Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly things can turn ugly quickly. I would like to use a...
10
by: Jes | last post by:
Dear all I have a date field on a HTML form where the user is asked to key in dd/mm/yyyy However, when that is written to MySql it is either not accepted or another value is tored in the...
3
by: murch.alexander | last post by:
I made a simple public function to set and return a date value (see below). I have a number of queries that call up the function to get the "As Of Date," which is typically set to today's date....
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
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...
0
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,...
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.