Change text depending on the date

Hey, I want the text to change according to the date. Eg: If it’s 9 May, display Mother’s Day. If it’s 25 December, display Christmas day with the relevant link in the button.

I don’t have much coding knowledge and want someone to guide me on how to achieve this.
Thanks.

Hey there. You would need to use a collection for this.
You can create a collection with these columns:

  1. Date

  2. Display Text

  3. Link

Then you can write some code to get todays date, and query the database based on that. And then get the item which matches the condition, and use that to display the data and set the link.

I hope this was helpful. You can contact me if you need any specific code for this.

Best,
Wix Freaks

Hey, thanks for your reply! I created a collection with the columns you mentioned above: Date, Display Text and Link.
Now, I’d like to get today’s date, fetch the text and link from the relevant row and then display it in the text box and the link in the button. To achieve that, I want your help with the code.

Thanks for your help.

Please read the Forum Guidelines. You will not request code. The idea is to try it yourself first and if that doesn’t work, show us the code and we’ll help you further. But first, you will have to put your back into it yourself. If you cannot or do not want to, there are many Velo Prof’s out there you can do it for you, paid.

Sorry for that. Here’s the code I tried that has errors and does not work the way I want:

import wixData from 'wix-data'; 

function filterDB(){
    wixData.query("Wishfindr")
 .find() 
 .then( (results) => { 
 //I want to check the date column of collection 'Wishfindr'
                results.date((result)=>{
 //if the field of the record matches today's date, display the text and link in button
 let today = new Date();
 if (result.date = today){
                    let text = itemData.textfortodaybox;
                    let link = itemData.linkfortodaybox;
                    $w('#text85').text = "Today: " + text
                    $w('#button27').link = link
 }
 }); 
 })
 .catch( (err) => { 
 let errorMsg = err;
 } );

This code is unable to check the date column and display the text, link in button.
Could you please help me correct it?

OFF-TOPIC.
@Tube Relevant

I got your message, but could not reply.
Here you will find your answer…
https://www.wix.com/velo/forum/coding-with-velo/resolved-wix-database-and-code-files-not-loading

@russian-dima Hey, thank you so much for that. Could you please also answer the question above and help me correct the code?

Did you read Giris post? Did you already have tried it on your won ?
What do you think how much time you will need to learn new coding stuff?
This will surely not happen withing few hours and perhaps also not within few day. Perhaps even not within few month. You should read more posts related to the DATE-TOPIC.

Where did you got this part of code?
Where did you define —> “itemData” ???

let text = itemData.textfortodaybox;
let link = itemData.linkfortodaybox;

Ok, how to solve your problem by your own?
Start simple with this code here…

import wixData from 'wix-data'; 

const DATABASE = "Wishfindr"

$w.onReady(()=>{
   let today = new Date(); console.log("Todays-Date: ", today)
   filterDB();
});

function filterDB(){
   wixData.query(DATABASE)
   .find() 
   .then((results) => {console.log(results)
       let items = results.items; console.log("Found DB-Items: ", items)
   })
   .catch((err)=>{let errorMsg = err; console.log(errorMsg)
});

First analyse your own RESULTS.
Take a look into —> CONSOLE and understand first whatts happening.
Post your OUTPUTS (screenshot). And perhaps also upload a screenshot of your DB, which would make working easier.

I hope to see, that you also followed → WixFreaks advise…

You can create a collection with these columns:

Date

Display Text

Link

Hey, thanks for your advice! I tried to understand and modify the code for my issue.

Here’s a screenshot of my Database:

The field key of the Wishfindr (Link…) column is ‘link-items-1-title’
The field key of the Text for Today Box column is ‘textForTodayBox’
The field key of the Date-1 column is ‘date1’

As you can see, I have stored the dates as Text in my collection. So I modified the code to get the date in the ‘Text’ form instead of ‘Date and time’.

Here’s the code:

import wixData from 'wix-data'; 

const DATABASE = "Items 1"

$w.onReady(()=>{
   filterDB();
});

function filterDB(){
   wixData.query(DATABASE)
 .find() 
 .then((results) => {console.log(results)
 let items = results.items; console.log("Found DB-Items: ", items)
 
 const todaydate = new Date();
 const options = {
      day: "numeric",
      month: "long",
      year: "numeric"
 };
 //I want the column 'date' from DATABASE and find today's date within it's cells.
 let today = todaydate.toLocaleDateString("en-US", options);
 const dateincollection = $w("#dynamicDataset").getCurrentItem().date1;
 let text = $w("#dynamicDataset").getCurrentItem().textForTodayBox;
 let link = $w("#dynamicDataset").getCurrentItem().link-items-1-title;
 if (today = dateincollection){
          $w('#today').text = "Today: " + text
          $w('#todaybutton').link = link
 }
 } )
 .catch((err)=>{let errorMsg = err; console.log(errorMsg)
})}

I’m not sure if it’s properly able to take data from the date1 field, compare it with today’s date and write the text. Can you point out the mistakes and help me with this?

I managed to do it!
Here’s the code I used.

import wixData from 'wix-data';
$w.onReady(function () {
 let localDate = new Date();
 let yearValue = localDate.getFullYear();
 let monthValue = localDate.getMonth();
 let dayValue = localDate.getDate();
 let dateValue1 = new Date(yearValue,monthValue,dayValue,0,0,0);
 let dateValue2 = new Date(yearValue,monthValue,dayValue,23,59,59);

    wixData.query('Items 1')
 .between('date', dateValue1, dateValue2)
 .find().then(results => {
        console.log(results)
 let todaytext = results.items[0].textForTodayBox;
 let todaylink = results.items[0].link_items_1_title;
        $w('#today').text = 'Today: ' + todaytext
        $w('#todaybutton').link = 'https://tuberelevant.com' + todaylink
 });
});

Hello, Can we do same thing with booking calendar.