473,509 Members | 2,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding a serial number of a day.

14 New Member
what is the java script source code to find the serial number of a date of a year.
Aug 22 '10 #1
7 4563
gits
5,390 Recognized Expert Moderator Expert
may i ask what a 'serial number of a date of a year' is? never heard of it - could you give an example or link to it?
Aug 23 '10 #2
Udara chathuranga
14 New Member
The serial number of 1900.01.01 is 1.
The serial number of 1901.01.01 is 365.
Serial number is the system assigned number for a date from the day 1900.01.01
Aug 23 '10 #3
gits
5,390 Recognized Expert Moderator Expert
in that case it is basically the day difference to the base date. a simple way could be to extend the JavaScript date object like this:
Expand|Select|Wrap|Line Numbers
  1. Date.prototype.getSerialDateNumber = function() {
  2.     var baseDate = new Date(1900,1,1);
  3.  
  4.     // one day based on ms
  5.     var oneDay = 86400000;
  6.  
  7.     var dayDiff = Math.ceil(
  8.         (this.getTime() - baseDate.getTime()) / oneDay
  9.     );
  10.  
  11.     return dayDiff;
  12. }
  13.  
  14. var d = new Date;
  15.  
  16. alert(d.getSerialDateNumber());
Aug 23 '10 #4
Udara chathuranga
14 New Member
Expand|Select|Wrap|Line Numbers
  1. <html><head><title>Day counter</title>
  2. <script language="javascript">
  3.    Date.prototype.getSerialDateNumber = function() {
  4.        var baseDate = new Date(1900,1,1);
  5.        //this is the date that i want to find the serial number--------I add this
  6.     var mydate=new Date(1900,1,31);
  7.     // one day based on ms
  8.     var oneDay = 86400000;
  9.  
  10.  
  11.        var dayDiff = Math.ceil(
  12.          (mydate.getTime() - (baseDate.getTime()-oneDay)) / oneDay 
  13.          //"oneDay" should be abstracted from baseDate.getTime() to get the right answer isn't it...
  14.     );
  15.  
  16.  
  17.      return dayDiff;
  18.  
  19.  }
  20.  
  21.   var d = new Date;
  22.  
  23.  alert(d.getSerialDateNumber());
  24.  
  25. </script>
  26. </head>
  27. <body>
  28. </body>
  29. </html>
  30.  
Thank you very much sir, I understood your code and I have done some changes On it. Is it a good change or a bad one. Please reply. How ever thank you very much for your help.
Aug 25 '10 #5
gits
5,390 Recognized Expert Moderator Expert
it works for this case ... but you wouldn't have needed it ... in line 21 of your last code post the following would have done the job:

Expand|Select|Wrap|Line Numbers
  1. var d = new Date(1900,1,31);
your change fixes the output to a specific date and makes the date-extension nearly useless ... which could give you the serial date number for any date without your change - so ... you might judge your change for yourself ... what would you say? bad or good change? :)
Aug 25 '10 #6
gits
5,390 Recognized Expert Moderator Expert
ahh ... and we need a fix for the baseDate:

Expand|Select|Wrap|Line Numbers
  1. new Date(1900,1,1)
  2.  
  3. // is: Thu Feb 01 1900 00:00:00 GMT+0100 (CET)
  4.  
  5. // while:
  6.  
  7. new Date(1900,0,1)
  8.  
  9. // is: Mon Jan 01 1900 00:00:00 GMT+0100 (CET)
so the month starts at 0 for january ... just overlooked it before :) you might have a look here for a reference to the JavaScript Date object.
Aug 25 '10 #7
Udara chathuranga
14 New Member
Thanks, Now your code is working properly. Please be in touch.
Aug 26 '10 #8

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

Similar topics

3
13928
by: Niy | last post by:
what does that mean? what for? I searched a lot but failed to find explanation. Sometimes I really have difficulty finding documentation for some views.
15
9627
by: tom | last post by:
Hi, How do I get the serial number of the harddisk in .NET? I want this to be the same number even if the user has reformatted, so I do not want the volume serial number. Thanx, t
5
2662
by: | last post by:
Hi, Do memory sticks have serial numbers like harddrives? If so how can I get this, I want to uniquely identify a memory stick (removable drive) for authentication. Thanks
79
13963
by: Klaus Bonadt | last post by:
In order to protect software from being copied without licence, I would like to use something like a key, which fits only to the current system. The serial number of the CPU or the current...
3
5653
by: Mark Harris | last post by:
I have an installer which uses a Customer Information page in it, is there an easy way to pass the serial number entered to a custom action? If not, where would i find the serial number in the...
5
7038
by: Tayyab | last post by:
Hi, If you understand the subject of my post that means you would know why i want this. Please dont give me the code for Volume number as i am talking about manufacturer serial number. I am working...
14
28079
by: Lauren Wilson | last post by:
Discovered this interesting comment on MSDN: "To programmatically obtain the hard disk's serial number that the manufacturer assigns, use the Windows Management Instrumentation (WMI)...
9
20648
by: Nebojsa4 | last post by:
Hi. First, sorry on my weak English to all. Qusetion: How to read (in VB) Manufacturer serial number of Hard disk drive? Not volume/serial number of C:, D:, etc. partitons. For reading...
0
7237
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
7137
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
7347
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,...
1
7073
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...
0
7506
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
5656
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,...
0
4732
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...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.