Inserting dates into a SQL platform

I am currently facing an issue where the date is being inserted into the SQL database as 30/12/1899. I am using Access 2003 for the database and cannot determine why this unexpected behavior is occurring!

window.status='Loading contingency scripts - please wait...';
audit('Loading contingency scripts');
var conting={ i:0

,start:function(){
    window.status='Loading form - please wait...';
    var t='';
    t+='<form name="frm_conting" id="frm_conting" onsubmit="return false;">';
    t+='<table width="100%" cellspacing="1" cellpadding="0">';
    t+='<tr><td>Date (DD/MM/YY):</td><td><input type="text" size="8" value="'+current_date+'" id="date"></td></tr>';

t+='<tr><td>Time Started:</td><td><select id="timefrom"><option></option>';
  for(h=8;h<23;h++){  
      for(m=0;m<46;m=m+15){  t+='<option value='+nb[h]+':'+nb[m]+'>'+nb[h]+':'+nb[m]+'</option>';  };
     };
t+='</select></td></tr>';

t+='<tr><td>Time Finished:</td><td><select id="timeto"><option></option>';
  for(h=8;h<23;h++){  
  for(m=0;m<46;m=m+15){  t+='<option value='+nb[h]+':'+nb[m]+'>'+nb[h]+':'+nb[m]+'</option>';  };
     };

    t+='</select><tr><td>Extension #:</td><td><input type="text" size="5" value="'+my.extension+'" id="staffid"></td></tr>';
t+='<tr><td>Desk ID:</td><td><input type="text" size="5" value='+my.deskid+' id="desk"></td></tr>';
    t+='<tr><td>Number of calls:</td><td><input type="text" size="5" id="calls"></td></tr>';
    t+='<tr><td>Avid ID:</td><td><input type="text" size="5" id="avid"></td></tr>';
    t+='<tr><td><input type="button" value="Submit" onClick="conting.save()"></td>';    
    t+='</table>';
    t+='</form>';

    div_form.innerHTML=t;       
    window.resizeTo(400,385);
    window.status='';
    }

,save:function(){
var conting_date=frm_conting.date.value; 
 if(!isdate(conting_date)){alert("You have entered an incorrect date.");return false;};

var conting_timefrom=frm_conting.timefrom.value; 
var conting_timeto=frm_conting.timeto.value; 
 if(conting_timefrom==''||conting_timeto==''){alert("You need to enter a starting & finishing time.");return false;}; 
 if(conting_timefrom>conting_timeto){alert("The time you have entered is after the finish time.");return false;}; 

var conting_staffid=frm_conting.staffid.value; 
 if(conting_staffid.length!=5) { alert("You have entered an incorrect extension number.");return false;};

var conting_desk=frm_conting.desk.value; 
 if(conting_desk.length!=5) { alert("You have entered an incorrect desk ID.");return false;}; 

var conting_calls=frm_conting.calls.value; 
 if(isNaN(conting_calls)){alert("You have not entered amount of calls.");return false;};

var conting_avid=frm_conting.avid.value; 
 if(isNaN(conting_avid)){alert("You have entered an incorrect avid ID.");return false;};
 if(conting_avid.length!=5) { alert("You have entered an incorrect avid ID.");return false;}; 

 conn.open(db["contingency"]);
 rs.open("SELECT MAX(prac_id) FROM practice",conn);
var prac_id=rs.fields(0).value+1;
var prac_staffid=frm_conting.staffid.value; 
var prac_date=frm_conting.date.value; 
var prac_timefrom=frm_conting.timefrom.value; 
var prac_timeto=frm_conting.timeto.value; 
var prac_calls=frm_conting.calls.value; 
var prac_avid=frm_conting.avid.value; 
 rs.close();
var q="INSERT INTO practice (prac_id, prac_staffid, prac_date, prac_timefrom, prac_timeto, prac_extension, prac_desk, prac_calls, prac_avid) VALUES ("+prac_id+","+my.id+", "+prac_date+", '"+prac_timefrom+"', '"+prac_timeto+"', '"+my.extension+"', '"+my.deskid+"', '"+prac_calls+"', '"+prac_avid+"')";

 rs.open(q,conn); 
 conn.close();
     alert("Your contingency times were successfully added.");
     window.status='';
   conting.start();
 }

 };
 window.status='';

Answer №1

Did you know that 30/12/1899 is considered the "zero" date of Access database?

If the prac_date variable seems to be causing issues, it's possible that it doesn't have the correct datetime value. Make sure to check for any missing, incomplete, or malformed data before running the query. It might be helpful to alert or log the value before executing the query to ensure its accuracy.

For further information on a similar topic, consider checking out this discussion on the MSDN forum.

Answer №2

One scenario that could explain the issue is: - When no text is entered or retrieved properly, it may default to 0 which represents T0 time in either Javascript or the database system. - Another possibility is that if the entered text is in the format 31/12/99, the two-digit year may be mistakenly interpreted as 1899 in the database. To avoid this problem, make sure to explicitly format the date in your insert query.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Executing test spec before promise resolution in $rootScope.$apply() is completed

When writing angular unit tests using Jasmine with angular-mocks' httpBackend, I successfully mocked my backend. However, one of my tests is encountering issues with an http call where a value is set to scope after the request is complete (in then()). ...

There is currently no loader set up for ".html" files within the Vitejs configuration, specifically for the index.html file

Hello, I have encountered a problem. I am working with Visual Studio 2022 and have created two projects within one solution - one for the back-end (ASP.NET) and the other for the front-end (Vue.js and Vite). The issue arises when I use the npm create vue@3 ...

Finding descendants using a jQuery object that has been saved

As I cycle through some unordered lists, I aim to retrieve all of the descendants using the saved jquery-wrapped selectors. Below is the HTML snippet: <ul> <li><a href="#">item 1</a></li> <li><a href="#"> ...

JavaScript and jQuery Conceal and Reveal

I'm having trouble with my jQuery hide and show functions. They seem to be working, but the items are not appearing on the page. I suspect it could have something to do with a parent element being positioned relative or having a display of none, but I ...

"Deleting a specific element from an array schema in a Node.js application

I need to update my database by setting ProjectSubmit.pending = true in order to remove accepted proposals. However, I also added these proposals to an array schema when they were accepted, and now I need to remove that index from the array. Here is my sc ...

"Encountering difficulties in utilizing the Chrome message passing API through Selenium's execute_script function

Currently, I am trying to send a value to a chrome extension from a browser automation script by invoking the chrome.runtime.sendMessage API from Selenium. Below is the python code I am using: import os import time from selenium import webdriver from sele ...

Eliminate HTML tags and formatting, but retain the anchor tags within the string

I have a string variable with HTML content that I need to clean up by removing all tags and formatting, while still preserving anchor tags for clickable links. content = "<div><a href=\"1\">I</a> was going here and then <a h ...

Retrieve the value from the socket client and store it in a

I have a query regarding updating socket values from another JS file. How can I achieve this? App.js io.on('connection', function (socket) { socket.currentRoomId = 0; socket.currentRoomName = "Loading..."; socket.currentRoomOwner = ...

Python Query: Best Practices for Saving DataFrames to CSV Files - Understanding Naming Conventions

Every half hour, I need to retrieve data from a table and my query specifically selects updated rows only. dfsql = client.query(sql, project=project_id).to_dataframe() Initially, I created a dataframe from an existing table and saved it as follows: dfsq ...

What is the best way to apply a hover effect to a specific element?

Within my CSS stylesheet, I've defined the following: li.sort:hover {color: #F00;} All of my list items with the 'sort' class work as intended when the Document Object Model (DOM) is rendered. However, if I dynamically create a brand new ...

If the checkbox is selected, the shipping address will automatically be set to the billing address, and the form will

My website has two address forms: one for billing and the other for shipping. When a user checks the "ship to same address" checkbox, the shipping form is hidden. Prior to clicking on the checkbox, the form does not submit correctly. However, when the che ...

Identifying static super method within an ES6 class

My goal is to have a base class and a subclass with class types that each have a static method identifying them using a string. This will enable me to easily look up handlers for different types in an object. I initially tried storing the class directly in ...

Does a NOT NULL constraint become unnecessary when a column already has a default value?

Consider this scenario... CREATE TABLE phone ( id integer primary key, country_code integer default 1, area_code integer not null, number integer not null ); I am debating whether it is safe to eliminate the not nul ...

Next.js throwing an error: TypeError - attempting to read property 'map' of undefined

I am facing an issue with my Next Js project. I have implemented the backend logic to display data, but when I attempt to show all the data using the useEffect hook and the map function, I encounter the following error: TypeError: Cannot read property &apo ...

Looking to retrieve the full browser URL in Next.js using getServerSideProps? Here's how to do

In my current environment, I am at http://localhost:3000/, but once in production, I will be at a different URL like http://example.com/. How can I retrieve the full browser URL within getServerSideProps? I need to fetch either http://localhost:3000/ or ...

The Carousel Slider seems to encounter issues when trying to implement it with *ngFor in Angular 8

Currently tackling an issue in Angular 8 where my slider functions perfectly with static data. However, upon attempting to loop through some dynamic data, the 'left' and 'right' buttons on the carousel cease to work. The images also fai ...

Make sure accordion items stay open even when another one is clicked

I have implemented an accordion component that currently opens and closes on click. However, I am facing an issue where clicking on one item closes another item that was previously open, which is not the behavior I desire. I'm unsure of the best appro ...

Text alignment issues cause animation to vanish

Utilizing particles.js, I set up a full-screen particle effect by specifying the animation to be full-screen with height: 100vh;. This worked perfectly as intended. However, when attempting to add text on top of the particle animation and center it vertica ...

Is there a way to use jQuery to centrally align the accordion item that I have chosen?

My attempts to use `this.scrollIntoView({behavior: "smooth"}) were yielding inconsistent results in terms of where the selected item would land on the page. I believe I might need to utilize scrollTop(), but as someone who is new to jQuery, I am ...

Turborepo users encountering peculiar errors with Remix integration

Currently, I am working on integrating a remix example for my library, react18-themes, and have a functional example available here. However, I am facing some unusual errors when attempting to set up the example in the monorepo. TypeError: Unknown file ext ...