Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

92
Views
How do I show the last visit on my website with a cookie?

The basic idea is that every time somebody visits the website the cookie saves the time and date. If the user then visits the website multiple times the cookie only shows the date and time when the user last visited. At the moment I have the following code which does work put obviously always updates the date and time:

var today = new Date();
var date = today.getDate()+'-'+(today.getMonth()+1)+'-'+today.getFullYear();
var time = today.getHours()+':'+today.getMinutes()+':'+today.getSeconds();
var dateTime = date+' at '+time;
document.cookie ='last_visit='+ dateTime 

Edit:For other people who might need help, the following code seems to work:

var today = new Date();
var date = today.getDate()+'-'+(today.getMonth()+1)+'-'+today.getFullYear();
var time = today.getHours()+':'+today.getMinutes()+':'+today.getSeconds();
var dateTime = date+' at '+time;
function getCookieValue(a) {
    const b = document.cookie.match('(^|;)\\s*' + a + '\\s*=\\s*([^;]+)');
    return b ? b.pop() : '';
}
console.log ("getCookieValue " + getCookieValue("last_visit"));
document.cookie ='last_visit='+ dateTime
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You cannot share visited data between users on the cookies without receiving data from the server.

The solution is to save the last visit DateTime into the Database and send it back to the client

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!