#How do I get timestamp of exact time in sql?
92 messages · Page 1 of 1 (latest)
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
✅Marked as resolved by OP
I have tried using all functions to get current time in sql but it's only showing current date
by using TIMESTAMP or DATETIME as datatype. not just DATE
Ohh
ok
I'm getting timestamp not of my timezone
idk why
It's showing 6 hours before
my timezone
either your DBMS or your node process are using a different timezone then
Ahh, how do I fix it then?
what timezone is that? UTC+-x
that db entry is in UTC
o, so how do i make it in my timezone?
any idea/
by displaying it as a timestamp!
yeah
internally time should always be stored in UTC, so that's totally correct and valid
just show 5 hours 30 minutes ahead in timestamp?
oh
Is that a good solution for it?
No
How do you intend to display the time
On discord?
yeah
Message formatting (mentions, timestamps, emoji, etc.): learn more
Use the time function from djs to parse it to a timestamp
Ok, ty!
Or optionally just <t:seconds:flag>
Also it don't happens like this in mongoose, idk why it happens like this in sql
That automatically converts it to the timezone of the user looking at it
it does, you just don't look at it raw like you do in your SQL DBMS
ah
uhh
I am not able to convert it into timezone
it's not getting converted into my timezone
this is the method I'm using
You dont need to convert it
Discord does that
so what do i do?
convert this timezone into milliseconds?
Seconds
and then use this?
Yes
uhh
...
Replace flag with the actual flag
In this case, should I use this?
or this one
One is styled, one isnt
Try it out, choose for yourself
Alright
and scroll down a bit further for examples of all styles
The time is still showing not of my timezone
This is what the timestamp I retrieved from database
which I converted into seconds
Using this method
that... looks like it's in your timezone though
not really so
because the time you stored in the DB is not now
oh yea
i forgot about that
lemme try doing now then
uhh this one i just did
and it's showing some other time
if u don't mind, can you try converting that timestamp in your system?
you don't show me the timestamp though...
and how did you save it to your db? what's the actual query you use for insert?
When creating the table I have made the timezone as default so whenever I insert into, it just sets the timezone automatically
let sql = `INSERT INTO Modlogs(Guild_id, User_id,Moderator_id,Punishment_type,Reason ) VALUES ('${interaction.guild.id}', '${warnUser.id}', '${interaction.user.id}', 'Warning', '${reason}')`;
con.query(sql, function (err, result) {
if (err) throw err;
});
like this
well, what DBMS are you using? MySQL, Postgres, sqlite, ...?
MySQL
So this timezone is of the hosting database?
👆 yes
So can I try like adding the difference of seconds of their timezone and my timezone to it, so it matches
or you could set the timezone on your DBMS to match yours. as shown on the page I linked
can you tell in short, bcoz its making a less sense to me
that page has the syntax explained as well as examples. did you even bother to read it?
Yeah ofc I did
I think it's related here
But this part I am confused
then ask a question about parts you didn't understand instead of asking me to explain it completely
I am confused in this part
that's not a question. that's just stating "I don't understand"
Honestly saying I am not making any sense here, if you could give me some hint of starting so I could try to guess what the other part is saying. If you don't wanna tell, that's fine thanks.
the hint would be to read that page... if nothing on that page makes any sense to you you might want to take a course on MySQL syntax first