473,586 Members | 2,681 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 4574
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
13946
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
9663
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
2673
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
14026
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 operating system would be appropriate. However, I do not know how to retrieve the information. Could you help? Klaus
3
5659
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 registry? I'm using C# for the custom action -- Mark Harris
5
7060
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 on C# and I know about win32_PhysicalMedia to retrieve the manufacturer serial number but that does not work for Win 2000 and I want something that...
14
28108
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) Win32_PhysicalMedia (a class) property SerialNumber." I'm sorry to admit it bit I am really undereducated on how to incorporate some of the Windows SDK...
9
20687
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 volume/serial number of hard disk C: etc, You can use Microsoft Scripting Runtime (in VB):
0
7912
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...
0
8202
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. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
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...
1
5710
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...
0
5390
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...
0
3837
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...
1
2345
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 we have to send another system
0
1180
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...

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.