Question: I've been trying to use a Single JavaScript object in multiple files. For that I chose singleton design pattern in JavaScript.

**mySingleton.js**

```
var mySingleton = (function () {
var instance;
function init() {
function privateMethod(){
    console.log( "I am private" );
}
var privateVariable = "Im also private";
var privateRandomNumber = Math.random();

return {

  publicProperty: "I am also public",
  publicMethod: function () {
    console.log( "The public can see me!" );
  },

  getRandomNumber: function() {
    return privateRandomNumber;
  }

  };

};

return { 

getInstance: function () {
  if ( !instance ) {
    instance = init();
    console.log("Newly creating an object");
  } 
  return instance;
} 
};
})();
module.exports = mySingleton;

```

And i'm Accessing the The above object in a separate node js file. As showed in following code

**test.js**

```
var singleton = require('./mySingleton');
var obj = singleton.getInstance();
console.log(obj.publicProperty);
console.log('random number value:'+obj.getRandomNumber());

```

**test2.js**

```
var singleton = require('./mySingleton');
var obj = singleton.getInstance();
console.log(obj.publicProperty);
console.log('random number value:'+obj.getRandomNumber());

```

When i execute the above two files each time a new javascript object is creating. But I want to use the same JavaScript object in multiple files.

Thanks in advance....

So Can anyone please give any suggestion to achieve the above functionality.

Answer: 
The query should work if you stored only dates in `Dateofbirth`. If you try the following script you'll get the expected results, `AAA`, `BBB`:

```
create table students(
    ID int primary key identity,
    Name varchar(50),
    Dateofbirth datetime)

insert into students (Name,Dateofbirth)
values ('AAA','2014-10-03'),
    ('BBB','2014-10-03'),
    ('CCC','2014-10-04')

select * 
from students 
where Dateofbirth between '2014-10-03' and '2014-10-03'

select * 
from students 
where Dateofbirth>='2014-10-03' and Dateofbirth<='2014-10-03'

```

I suspect you store birth dates using a `datetime` column. `datetime` includes time which means that a `2014-10-03` actually is `2014-10-03 00:00:00`. I suspect that either a bug or an ETL quirk adds a time component, perhaps in the form of a time zone offset?

You should change the column's type to `date`, which stores only dates. This makes business sense as I doubt that you want to store the actual birth time of students, and prevents accidental time entries.

If you don't want to change the column's type, you can cast the field's value to `date` before comparing. Normally, applying any kind of operation on a field value means you can't use any underlying indexes. In this case SQL Server is smart enough to detect the cast and use any underlying indexes on the `Dateofbirth` column: 

```
select *
from students 
where cast(BirthDate as date)>='2014-10-04' and cast(BirthDate as date)<='2014-10-04'

```

You'd still have to clean up the dirty Dates of Birth though, to remove any unwanted time components.
As already mentioned, the time-part of your column (hour/minute etc) is the reason for that behavior.

In T-SQL, you can also use [DATEDIFF](http://msdn.microsoft.com/library/ms189794.aspx) to get the data for one specific date:

```
SELECT * FROM student
WHERE DATEDIFF(d, Dateofbirth, '2014-10-03') = 0

```