This is an interesting problem. As an R question it would, of course, be off topic for the site. You already have one solution from EdM regarding setting the starttime
and stoptime
variables in the Surv
command: this effectively defines the time-dependent risk set treating diagnosis date as Day 0 or Time 0. What you are modeling with this approach is a flexible non-parametric baseline hazard function as a function of time from diagnosis and not time from entry into study.
The problem is that there are many "times" which can be predictive of outcomes: there is for instance the patient's age, or the calendar year, or time from entry into study (either initiation of treatment or signing informed consent). These are broadly referred to as the age, period, and cohort effects.
You might be surprised to learn left truncation as a solution to immortal time bias is less common than you expect. For instance, in every cancer study I have supported, not one has modeled event time from diagnosis or time from last treatment. The truth is, if the "gap" exists for every patient in the sample, the associated Nelson-Aelan curve is very misleading because the incidence is, by definition, 0 per person-time from time 0 until the first observed failure. Note: you can't even estimate a Kaplan Meier because not all subjects are at risk (for a measurable event) at time 0. Adjusting the start and stop times affects whom you compare to whom, but this approach still cannot account for subjects who died prior to inclusion in the sample. If you are lucky enough to sample a few subjects in the early time period, it's important to handle these events appropriately, and in this case, EdM's approach is a valid --but not the only-- approach to get a stable estimate of incidence over time. The approach should also be justified by the proportionality of the hazard ratios as assessed by plots and tests if need be.
I actually disagree with the way most time-to-event analyses are conducted for cancer studies, but not for that reason! As you know, a Cox model is a very flexible model in that it is semi-parametric in how it handles an arbitrary baseline hazard function (as a default or in multiple groups via stratification), and it handles censoring. A cox model also allows for adjustments like in a regression model. I actually believe time from entry into study should be the time 0 because this time is the most "artificially" constructed time; that is to say, when generalizing the results there is no need to "predict" time from entry into study for a patient (not subject) who's not actually in a study. For generalizable times like time from diagnosis, calendar year, etc. you can simply adjust for these as variables in the model. Depending on the sample size, you can use more and more sophisticated approaches like splines to estimate other time-dependent incidence parameters.
Stephen Senn has written extensively on the benefits of adjusting for prognostic variables, even in randomized ITT analyses. I agree with him and would suggest, depending on the analysis, and the nature of the functional shape of the hazard function, entry-into-study is a reasonable choice of time 0, and other predictive "times" can be handled as variables in the model. Note: these would not be time varying functions since, from study entry, age, cohort, and period all move in unison, so the typical adjustments would be "age at study entry" or "years since initial diagnosis at study entry" or "drug-free interval" all measured in clinically relevant units.