# Looking for best practice for "task and time" tracking with obsidian

**URL:** <https://forum.obsidian.md/t/looking-for-best-practice-for-task-and-time-tracking-with-obsidian/79342>\
**Category:** Help\
**Created:** [March 27, 2024, 9:59am UTC](https://forum.obsidian.md/t/looking-for-best-practice-for-task-and-time-tracking-with-obsidian/79342 "2024-03-27T09:59:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aguylookingforstuff](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@aguylookingforstuff](https://forum.obsidian.md/u/aguylookingforstuff)\
**Post date:** [March 27, 2024, 9:59am UTC](https://forum.obsidian.md/t/looking-for-best-practice-for-task-and-time-tracking-with-obsidian/79342/1 "2024-03-27T09:59:17Z")

</div>

### What I’m trying to do

I am looking for your best practices on task tracking.

I am using daily notes to structure my day, with some boilerplate for the whole day followed by blocks where I currently write down the timeframe (10:00 -10:30 i.e.) and what I was working on, written as a comment. The comment includes a project tag.

I would like to have an overview on how much time I spent on each “project” over the course of the year.

As I understood it, most of the solutions out there use properties or tags, but I am not sure how to seperate between multiple entries in one notes-file. How are you handling that?

### Things I have tried

Playing around with templater, dataview, tracker.

---

<div class="post-metadata">

**Author:** ![vanadium](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/v/c4cdca/32.png) [@vanadium](https://forum.obsidian.md/u/vanadium)\
**Post date:** [March 27, 2024, 12:18pm UTC](https://forum.obsidian.md/t/looking-for-best-practice-for-task-and-time-tracking-with-obsidian/79342/2 "2024-03-27T12:18:40Z")

</div>

Dataview allows to calculate totals of found values. That would allow you to explicitly write down a “time spend” value. See [Dataview sum of all prices in table - #2 by smiggles](https://forum.obsidian.md/t/dataview-sum-of-all-prices-in-table/56297/2) for how dataview is used to calculate a sum. A search on tag would retrieve all instances independent on whether they occur in the same or different files.

---

<div class="post-metadata">

**Author:** ![aguylookingforstuff](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@aguylookingforstuff](https://forum.obsidian.md/u/aguylookingforstuff)\
**Post date:** [March 27, 2024, 1:14pm UTC](https://forum.obsidian.md/t/looking-for-best-practice-for-task-and-time-tracking-with-obsidian/79342/3 "2024-03-27T13:14:45Z")

</div>

Thanks for the answer. I thought about that, too.  
But how would a query look like that finds multiple entries per file?

I have data in one file like:

Project: Something  
Timespent: 0.5  
Comment:  
kasdjadklajsd

Project: Different  
Timespent: 0.25  
Comment:  
qweqweqweqwe

Project: Something  
Timespent: 1.25  
Comment:  
iuozuioizouzio

I only find a solution for dataview to aggregate all entries of timespent, and not distinguish by “project”.

But I think I am missing something…

---

<div class="post-metadata">

**Author:** ![DJP](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@DJP](https://forum.obsidian.md/u/DJP)\
**Post date:** [March 27, 2024, 1:49pm UTC](https://forum.obsidian.md/t/looking-for-best-practice-for-task-and-time-tracking-with-obsidian/79342/4 "2024-03-27T13:49:02Z")

</div>

I am not a dataview guru, but I think you would need to make separate entries for each project:

Project\_Something:: Timespent 0.5  
Project\_Different:: Timespent: 025

I will await a Dataview Master to correct this as needed.

---

<div class="post-metadata">

**Author:** ![holroy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/holroy/32/77699_2.png) [@holroy](https://forum.obsidian.md/u/holroy)\
**Post date:** [March 27, 2024, 2:21pm UTC](https://forum.obsidian.md/t/looking-for-best-practice-for-task-and-time-tracking-with-obsidian/79342/5 "2024-03-27T14:21:49Z")

</div>

You could try something like the following:

````auto

- [project:: Something] (timespent:: 0.5h)
	- kasdjadklajsd

- [project:: Different] (timespent:: 25 min) 
	- qweqweqweqwe

- [project:: Something] (timespent:: 1h 15min) 
	- iuozuioizouzio

## Queried version

```dataview
TABLE WITHOUT ID item.project as Project,
  item.timespent.minutes as Timespent, 
  item.children.text as Comments
WHERE file = this.file
FLATTEN file.lists as item
WHERE !item.parent
```

Total workload: `= round(sum(filter(this.file.lists, (l) => l.timespent).timespent).hours, 2) `h

````

If this is kept in a note of its own it should display something like (with local names instead of Norwegian 😛 ):

 ![image](https://forum.obsidian.md/uploads/default/original/3X/0/5/0503a1e73131ce60ca266586ad6bb1b2abf75456.png)

Here I’ve done the total calculation _outside_ of the table in a separate inline query focusing on the current file.

Similar queries can also be built over multiple files.

There are a few main points I would like to make though:

- To make _dataview_ pick up the information as fields you need to use syntax like above with double colons
- Fields are connected either to the page, or to a list/task context. To be able to keep the `project` and `timespent` together you need to have them in a list context. Otherwise they’re all collated into two (or more) separate lists of the `project` and `timespent` (and `comment)` .
- If you note the `timespent` as duration, it’s a lot easier to sum them up later on, and you can use `durationformat()` or similar measures to make it look pretty

This forum also holds various ways to do the summation of a column within the table (or as a postprocessing of the table).

---

<div class="post-metadata">

**Author:** ![aguylookingforstuff](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@aguylookingforstuff](https://forum.obsidian.md/u/aguylookingforstuff)\
**Post date:** [March 28, 2024, 10:14am UTC](https://forum.obsidian.md/t/looking-for-best-practice-for-task-and-time-tracking-with-obsidian/79342/6 "2024-03-28T10:14:49Z")

</div>

Thank you, that pointed me into the right direction.

I have created some dataviewjs code to group the entries together, not sure if this was the easiest way, but it was for me.

```dataviewjs

let page = dv.current()
const projectRegex = /\[project:: (.+?)\]/;
const timeRegex = /\(timespent:: (.+?)\)/;
let extractedValues = {};

page.file.lists.values.forEach((item, index) => {

    const jsonString = item.text;
    const projectMatch = jsonString.match(projectRegex);
    const timeMatch = jsonString.match(timeRegex);
    let projectName = '';
    let projectTime = '';
    
    if ((projectMatch && projectMatch.length > 1) && (timeMatch && timeMatch.length > 1)) {
        projectName = projectMatch[1];
        projectTime = timeMatch[1];
        
        if (typeof extractedValues[projectName] == "undefined") {
	        extractedValues[projectName] = {
		        comments: [],
		        time: projectTime,
		    };
        } else {
	          extractedValues[projectName].time = parseFloat(projectTime) + parseFloat(extractedValues[projectName].time);
        }
        
        item.children.forEach((comment, index) => {
	        extractedValues[projectName].comments.push(comment.text);
        });
    };
   
});

const projectsTableArray = [];
let i = 0;
for (let projectName in extractedValues) {
    if (extractedValues.hasOwnProperty(projectName)) {        
        let project = extractedValues[projectName];       
        let comments = "";
        for (let comment of project.comments) {
            comments += comment + "\r";
        }
        projectsTableArray[i] = [projectName, project.time, comments];
        i++;
    }
};

dv.table(["Projekt", "Zeit", "Kommentar"], projectsTableArray);

```

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [April 4, 2024, 10:15am UTC](https://forum.obsidian.md/t/looking-for-best-practice-for-task-and-time-tracking-with-obsidian/79342/7 "2024-04-04T10:15:23Z")

</div>

Closed on April 4, 2024, 10:15am UTC

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