# Convert date and time string into Raw / Epoch time

**URL:** https://community.mp3tag.de/t/convert-date-and-time-string-into-raw-epoch-time/59512
**Category:** Support
**Created:** [December 26, 2022, 9:15am UTC](https://community.mp3tag.de/t/convert-date-and-time-string-into-raw-epoch-time/59512 "2022-12-26T09:15:48Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![wneclass2018](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/w/cdc98d/32.png) [@wneclass2018](https://community.mp3tag.de/u/wneclass2018)
#### Post date: [January 7, 2024, 9:55pm UTC](https://community.mp3tag.de/t/convert-date-and-time-string-into-raw-epoch-time/59512/8 "2024-01-07T21:55:46Z")

</div>

> [@Lem](#):
>
> it should be:
> 
> **30** + (_ **23** _ x 60) + (_ **11** _ x 3600) + (_ **360** _ x 86400) + ((_ **2022** _ - 1900) - 70) x 31536000 + ... etc
> 
> Note: today is the 360th day of the year, but I don't know how to obtain the day-number of the year from digits 4 through 8 in the string (1226, i.e. Dec 26).

I have **SOLVED** your problem, in which you can verify with [https://www.epochconverter.com/](https://www.epochconverter.com/), and I also have you to thank for that because it was this example, "30 + (23 x 60) + (11 x 3600) + (360 x 86400) + ((2022 - 1900) - 70) x 31536000 + ... etc", provided by you, was what made it successful, given that I had been searching the net for info. I wasn't aware that %my\_year% (aka %tm\_year%), excluding when you have to acquire total days of the year (i.e. tm\_yday), had to be subtracted by 1900. Moreover, I solved your "tm\_yday" issue using your $add($if(x,y,z),%my\_day%). Nonetheless, here is the FULL SINGLE-line string to calculate EPOCH time, as well as the legends below the script, and when you employ it, per the example that you provided, which was " **2022-12-26 11:23:30**", your ANSWER will definitely be " **1672053810**".

Using, $add(A,B,C,D,E,F,'-'G,H):  
`$add(%my_second%,$mul(%my_minute%,60),$mul(%my_hour%,3600),$mul($add($if($eql(365,$regexp($num(%my_year%,4),'^((?:(?<![\d])(?:(?:[1-9][0-9]{2,}|[0-9]{2})(?:[13579][0-13-57-9]|[02468][1-35-79])|(?:[13579][0-13-57-9]|[02468][1-35-79]|[1-9](?:[0-9]{1,})?(?:[13579][0-13-57-9]|[02468][1-35-79])){1}00){1}(?![\d])){1})$',365)),$sub($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp(%my_month%,'^0*[01]$',0),'^0*2$',31),'^0*3$',59),'^0*4$',90),'^0*5$',120),'^0*6$',151),'^0*7$',181),'^0*8$',212),'^0*9$',243),'^0*10$',273),'^0*11$',304),'^0*12$',334),1),$sub($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp(%my_month%,'^0*[01]$',0),'^0*2$',31),'^0*3$',60),'^0*4$',91),'^0*5$',121),'^0*6$',152),'^0*7$',182),'^0*8$',213),'^0*9$',244),'^0*10$',274),'^0*11$',305),'^0*12$',335),1)),%my_day%),86400),$mul($sub($sub(%my_year%,1900),70),31536000),$mul($div($sub($sub(%my_year%,1900),69),4),86400),'-'$mul($div($sub($sub(%my_year%,1900),1),100),86400),$mul($div($add($sub(%my_year%,1900),299),400),86400))`

YYYY-MM-DD HH:MM:SS (I am assuming that "YYYY-MM-DD HH:MM:SS" is UTC), where:  
⯄ "YYYY" = "%my\_year%" or "%tm\_year%"  
⯄ "MM" = "%my\_month%" (aka FIRST half to solve for tm\_yday)  
⯄ "DD" = "%my\_day%" (aka SECOND half to solve for tm\_yday)  
⯄ "HH" = "%my\_hour%" or "%tm\_hour%"  
⯄ "MM" = "%my\_minute%" or "%tm\_min%"  
⯄ "SS" = "%my\_second%" or "%tm\_sec%"  
⯄ "tm\_yday" ⟷ `$add($if(x,$regexp($regexp(%my_month%,'^0*[01]$',0),'^0*2$',31)....,z),%my_day%) = "$add($if($eql(365,$regexp($num(%my_year%,4),'^((?:(?<![\d])(?:(?:[1-9][0-9]{2,}|[0-9]{2})(?:[13579][0-13-57-9]|[02468][1-35-79])|(?:[13579][0-13-57-9]|[02468][1-35-79]|[1-9](?:[0-9]{1,})?(?:[13579][0-13-57-9]|[02468][1-35-79])){1}00){1}(?![\d])){1})$',365)),$sub($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp(%my_month%,'^0*[01]$',0),'^0*2$',31),'^0*3$',59),'^0*4$',90),'^0*5$',120),'^0*6$',151),'^0*7$',181),'^0*8$',212),'^0*9$',243),'^0*10$',273),'^0*11$',304),'^0*12$',334),1),$sub($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp($regexp(%my_month%,'^0*[01]$',0),'^0*2$',31),'^0*3$',60),'^0*4$',91),'^0*5$',121),'^0*6$',152),'^0*7$',182),'^0*8$',213),'^0*9$',244),'^0*10$',274),'^0*11$',305),'^0*12$',335),1)),%my_day%)"`

In hindsight, I have created multiple strings such as strings that can read time formats like "YYYY-MM-DD HH:MM:SS[-+]HH:MM", as well as strings allowing, for example, 2022-13-25 09:43:20, where the month, "13" (or time is 3 digits or higher), and the year, "2022", will be AUTOMATICALLY be adjusted to "2023" and "January" (aka "01"), accordingly, and since you didn't specify, I am only including the simple string. Moreover, I use this string for column sorting via regular expression: "tm\_sec" (aka "%my\_second%") ＝ `"$regexp(%creation_time%,'^(?<![\d])(\d{4,})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})[Z](?=$)',$6,1)"`. The `"$if($eql(365,$regexp($num(%my_year%,4)...."`, which is the "x" of the "$add($if(x,y,z),%my\_day%)", is the EXCLUSIVE to NORMAL years (aka 365 days), while the "z" is for the LEAP year (basically, anything that is not "365 days").

**Now, I need help you. Do you know the formula to change/convert EPOCH time BACK into "YYYY-MM-DD HH:MM:SS", or just the Month, Day, and Year, given that hours, minutes, and seconds are easy to manipulate? I would really APPRECIATE that piece of information to accomplish an action file, making it whole. If you can find that information, just like the script above, I think that I can make it Mp3Tag compatible.**

---

_[View the full topic](https://community.mp3tag.de/t/convert-date-and-time-string-into-raw-epoch-time/59512)._
