# Personalized user greeting based on time of day

**URL:** https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101
**Category:** Ask for Help
**Created:** [June 13, 2024, 11:10am UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101 "2024-06-13T11:10:36Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![gannonatwork](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gannonatwork/32/91717_2.png) [@gannonatwork](https://community.glideapps.com/u/gannonatwork)
#### Post date: [June 13, 2024, 11:10am UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101/1 "2024-06-13T11:10:36Z")

</div>

Is there a more elegant way to accomplish this with less columns? I want to display a personal greeting to users on the home screen based on the time of day like:

#### 👋 Good morning, Jake!

I’ve got the TOD handled using a Math column, the challenge is how to handle the punctuation of the greeting when a user hasn’t added a username yet? As you can see in the screenshots below, I’m using a Template column to create the greeting based on TOD and then using ITE columns to remove the extraneously punctuation when usernames don’t exist.

There’s got to be a better way, right? It shouldn’t take 8 columns to accomplish this. Plus, I would prefer to have the greetings editable instead of hard-coded as parameters of a computed column. Ugh.

Any insight would be greatly appreciated. Thx

 ![Screenshot 2024-06-13 at 5.53.26 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/5/35afadb1df7f4f18994e00e928e73529fe906657.png)

 ![Screenshot 2024-06-13 at 5.54.20 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/4/b/4bcce0078debc55a92d04353a2398352464fa077.jpeg)

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [June 13, 2024, 11:18am UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101/2 "2024-06-13T11:18:24Z")

</div>

You don’t need separate if-then-else columns for each of morning/afternoon/evening. You can replace those with a single if-then-else column, something like:

- If TOD is less than 12, then Morning
- Else if TOD is less than 18, then Afternoon
- Else Evening

For the minimum number of columns, you could probably just pass the User’s name (or an empty string if no username) to a JavaScript column, and encapsulate all logic in that single column.

---

<div class="post-metadata">

### Author: ![Himaladin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/himaladin/32/71023_2.png) [@Himaladin](https://community.glideapps.com/u/Himaladin)
#### Post date: [June 13, 2024, 11:32am UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101/3 "2024-06-13T11:32:44Z")

</div>

If you are using JavaScript, you only need one column.

 ![Screenshot 2024-06-13 at 18.29.46](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/e/c/ecf530626fbbeb58401b784d9400ba0e639031fc.png)

```auto
function getTimeOfDay(p1) {
    const hours = p1.getHours();
    return (hours >= 5 && hours < 12) ? "Morning" :
           (hours >= 12 && hours < 17) ? "Afternoon" :
           (hours >= 17 && hours < 20) ? "Evening" : "Night";
}

function greet(p1, p2) {
    const timeOfDay = getTimeOfDay(p1);
    return p2 ? `👋 Good ${timeOfDay}, ${p2}!` : `👋 Good ${timeOfDay}!`;
}

return greet(new Date(), p2);

```

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [June 13, 2024, 11:44am UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101/4 "2024-06-13T11:44:31Z")

</div>

Yeah, I’d probably do something similar. Although passing the current time is redundant, especially when you call the function with `new Date()` 🤷‍♂️

Here is a modified version that only requires the user name as a single parameter:

```auto
function getTimeOfDay() {
    const hours = new Date().getHours();
    return (hours >= 5 && hours < 12) ? "Morning" :
           (hours >= 12 && hours < 17) ? "Afternoon" :
           (hours >= 17 && hours < 20) ? "Evening" : "Night";
}

function greet(p1) {
    const timeOfDay = getTimeOfDay();
    return p1 ? `👋 Good ${timeOfDay}, ${p1}!` : `👋 Good ${timeOfDay}!`;
}

return greet(p1);

```

 ![CleanShot 2024-06-13 at 19.43.48@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/9/697d93d936c426a11b1e15a41c95affbb8c57734.jpeg)

---

<div class="post-metadata">

### Author: ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)
#### Post date: [June 13, 2024, 11:56am UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101/5 "2024-06-13T11:56:49Z")

</div>

Including Current Time as a parameter, but not actually using it or referring to it in the code, does have an advantage because it will cause the javascript to run every 10 seconds and continuously update instead of caching. Could be useful if the app is open and the time flips between morning, afternoon, or evening.

---

<div class="post-metadata">

### Author: ![gannonatwork](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gannonatwork/32/91717_2.png) [@gannonatwork](https://community.glideapps.com/u/gannonatwork)
#### Post date: [June 13, 2024, 12:03pm UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101/6 "2024-06-13T12:03:55Z")

</div>

@Jeff_Hager To clarify your point, if I’m using a Glide table in this instance and leave the Current Time parameter in as @Himaladin suggests this won’t incur any updates or syncs that would count against my plan’s monthly quota, correct?

---

<div class="post-metadata">

### Author: ![Himaladin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/himaladin/32/71023_2.png) [@Himaladin](https://community.glideapps.com/u/Himaladin)
#### Post date: [June 13, 2024, 12:07pm UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101/7 "2024-06-13T12:07:45Z")

</div>

No, Glide only considers updates for actions: add, edit, delete, or sync with third parties.

---

<div class="post-metadata">

### Author: ![gannonatwork](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gannonatwork/32/91717_2.png) [@gannonatwork](https://community.glideapps.com/u/gannonatwork)
#### Post date: [June 13, 2024, 12:08pm UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101/8 "2024-06-13T12:08:28Z")

</div>

@Darren_Murphy @Himaladin @Jeff_Hager Just another example of why I like the Glide community so much — everyone is so generous with their time and willing to share their knowledge. A big thank you to all of you to rein in my exorbitant amount of columns. 😆 Much appreciated! 💯

---

<div class="post-metadata">

### Author: ![gannonatwork](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gannonatwork/32/91717_2.png) [@gannonatwork](https://community.glideapps.com/u/gannonatwork)
#### Post date: [June 13, 2024, 12:09pm UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101/9 "2024-06-13T12:09:17Z")

</div>

@Himaladin That’s what I thought, thx for confirming.

---

<div class="post-metadata">

### Author: ![gannonatwork](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gannonatwork/32/91717_2.png) [@gannonatwork](https://community.glideapps.com/u/gannonatwork)
#### Post date: [June 14, 2024, 1:46pm UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101/10 "2024-06-14T13:46:45Z")

</div>

@Darren_Murphy @Himaladin Quick follow up question on this JavaScript. Late last night I noticed the “Good morning” greeting was displaying before midnight. Since I want to the greeting to cover all hours of the day, I changed it to:

```auto
function getTimeOfDay() {
    const hours = new Date().getHours();
    return (hours >= 00 && hours < 12) ? "Morning" :
           (hours >= 12 && hours < 17) ? "Afternoon" :
           (hours >= 17 && hours < 24) ? "Evening" : "Night";
}

function greet(p1) {
    const timeOfDay = getTimeOfDay();
    return p1 ? `👋 Good ${timeOfDay}, ${p1}!` : `👋 Good ${timeOfDay}!`;
}

return greet(p1);

```

I’m confident the evening greeting will behave correctly, but want to see if my use of “00” for the morning greeting will run or should it be “0”? My experience with a 24-hour clock is that “00” is how the midnight hour is referenced but not sure if JavaScript will understand it that way? TIA

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [June 14, 2024, 1:50pm UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101/11 "2024-06-14T13:50:00Z")

</div>

It’s a number, so theoretically it should only be 0.

---

<div class="post-metadata">

### Author: ![gannonatwork](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gannonatwork/32/91717_2.png) [@gannonatwork](https://community.glideapps.com/u/gannonatwork)
#### Post date: [June 14, 2024, 2:00pm UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101/12 "2024-06-14T14:00:58Z")

</div>

Thx @ThinhDinh. Guess I was overthinking this since the Time of Day Math column in Glide will display “0” during the midnight hour. 😆

---

<div class="post-metadata">

### Author: ![Himaladin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/himaladin/32/71023_2.png) [@Himaladin](https://community.glideapps.com/u/Himaladin)
#### Post date: [June 14, 2024, 2:08pm UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101/13 "2024-06-14T14:08:06Z")

</div>

Do you have a different concept of evening and night time?

---

<div class="post-metadata">

### Author: ![gannonatwork](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gannonatwork/32/91717_2.png) [@gannonatwork](https://community.glideapps.com/u/gannonatwork)
#### Post date: [June 14, 2024, 2:53pm UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101/14 "2024-06-14T14:53:37Z")

</div>

No, just want to make sure the greeting is accurate all day and all night. 😀 This is a public app and we’ll have users active in the app late at night and super early in the morning depending on their time zone.

Thank you again for the JavaScript solution to this, something I definitely couldn’t have done on my own. 👍

---

<div class="post-metadata">

### Author: ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)
#### Post date: [June 21, 2024, 2:54pm UTC](https://community.glideapps.com/t/personalized-user-greeting-based-on-time-of-day/74101/15 "2024-06-21T14:54:15Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
